您的位置:首页 > 其它

Windows Azure Platform 2nd Edition Note 2

2012-01-29 23:47 218 查看
NamingService

-The Naming service allows youto assign DNS-capable names to your service, which makes the serviceeasilyresolvable over the Internet.

ServiceRegistry

-The AppFabric Service Busprovides a registration and discovery service for service endpoints called the serviceregistry.

classProgram

{

static void Main(string[] args)

{

ServiceHosthost = new ServiceHost(typeof(EnergyManagementService));

ServiceRegistrySettingssettings = new ServiceRegistrySettings();

settings.DiscoveryMode= DiscoveryType.Public;

foreach(ServiceEndpoints in host.Description.Endpoints)

s.Behaviors.Add(settings);

host.Open();

Console.WriteLine("Press[Enter] to exit");

Console.ReadLine();

host.Close();

}

}

The defaultsetting for the public discovery is set to private, so if you don’t set thediscovery type to

public, yourservice won’t be discoverable publicly

the serviceopens an outbound connection with a
bidirectional socket to

theAppFabric Service Bus relay service.Note that
you don’t need to open anyinbound ports in your firewall or NAT
router for the end-toend

communicationto work when using the AppFabric Service Bus. Therefore, the listenerapplication

can berunning behind a firewall, NAT router, and even with a dynamic IP address.Theclient

applicationinitiates an outbound connection to the relay service with the appropriateservice address

that can beresolved from the service registry. The AppFabric Service has a load-balancedarray of nodes

that providethe necessary scalability to the client and service communications. When theclient sends a

message tothe service, the message is relayed by the relay service to the appropriatenode that is holding

reference tothe listener’s endpoint. Finally, the relay service sends the message to theservice over the

listener’soutbound bidirectional socket.

AppFabricService Bus Bindings

Thefundamental difference between AppFabric Service Bus bindings and WCF bindingsis at the transport level, which is completely opaque to the programming model

MessageBuffer

TheAppFabric Service Bus bindings for the WCF-style communications are
designedfor synchronous

communicationsbetween the sender and the receiver. This means the receiver must be running to receive themessage sent by the sender; otherwise, the message will get lost TheAppFabric Service Bus offers a message buffer
service for storing messages in atemporary

cache forasynchronous communication between clients and servers.The messages stored in amessage buffer on the serverdon’t survive server reboots

Queues andTopics

Queuesprovide a durablemessaging mechanism, and Topics builds upon the queuing structure by adding theability to

createtopics for which consumers can create rules by which to filter messages

Note Queuesand Topics are replacing Message Buffers, which will be deprecated in futurereleases.

ProAzureEnergy Service Example

-Service Binding

-NetOnewayRelayBinding

-Relay Security

TransportClientEndpointBehaviorsharedSecretServiceBusCredential =

newTransportClientEndpointBehavior();

sharedSecretServiceBusCredential.CredentialType=

TransportClientCredentialType.SharedSecret;

sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerName=

issuerName;

sharedSecretServiceBusCredential.Credentials.SharedSecret.IssuerSecret=

issuerKey;

ServiceHostHost = new ServiceHost(serviceType);

Host.Description.Endpoints[0].Behaviors.Add(behavior);

-Message Security

Message security refers to thesecurity of the message as it travels from client to service via the AppFabric

Service Bus.As discussed earlier, the AppFabric Service Bus API offers four options formessage security

in theenumeration Microsoft.ServiceBus.EndToEndSecurityMode: None, Transport,Message, and

TransportWithMessageCredentials.netOnewayRelayBinding doesn’t support

TransportWithMessageCredentials.

-Service Endpoints

The endpoint

consists offour main attributes: the address of the endpoint, a binding that defines whatprotocol a

client canuse to communicate with the endpoint, a service contract that defines theoperations available

for theclient to call, and a set of behaviors defining the local behavior of theendpoint

<endpoint

address="sb://{yourservice namespace}

.servicebus.windows.net/OnewayEnergyServiceOperations/"

behaviorConfiguration="sharedSecretClientCredentials"

binding="netOnewayRelayBinding"

bindingConfiguration="default"

name="RelayEndpoint"

contract="EnergyServiceContract.IOnewayEnergyServiceOperations"/>

-Service Hosting

TransportClientEndpointBehaviorbehavior =

ServiceBusHelper.GetUsernamePasswordBehavior(issuerName,issuerKey);

Host = newServiceHost(typeof(OnewayEnergyServiceOperations));

Host.Description.Endpoints[0].Behaviors.Add(behavior);

Host.Open();

AppFabricMessaging: Queues and Topics

AppFabricService Bus Queues vs. Azure Storage Queues

So, what arethe differences, and when should each be used?AppFabric Queues provide a richer messaging environment in that it supportsprotocols other

than HTTP/S,in addition to enabling advanced messaging features:

• WCFbinding

• Poisonmessage handling

•Dead-lettering

• Transactions

• Groups

• Sessions

• duplicatedetection Message Deferral/Scheduled Delivery

•Authentication via ACS

Also, bothservices support REST over HTTP, but if you require a higher level ofperformance , you

can usebi-directional TCP with the AppFabric Queue

Another keydifference is that AppFabric Queues support the use of
sessions. With this, yougain the

ability toguarantee First-In First-Out ordering, as well as the ability to supportExactly-Once delivery

If any ofthe mentioned capabilities are required, you will need to use AppFabric Queues.If you

simply wantto use a queue to support cross-service communication, such as inter-rolecommunication

at scale,then AppFabric Queues could be overkill. In this case, Azure Storage Queuesshould be

sufficient.

**AddingSession State to a Queue

AppFabricService Bus Topics

HandlingProblem Messages and Abandonment

-Invalid/Poison Messages

-Server Error During MessageProcessing
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: