Exporteren (0) Afdrukken
Alles uitvouwen
EN
Deze inhoud is niet beschikbaar in uw taal, maar wel in het Engels.

MessageSender Class

The MessageSender class is used to send messages from the Service Bus. Although you can use the QueueClient class to send and receive messages without creating a MessageSender object, you can also use MessageSender and MessageReceiver to create a sender and receiver on an entity without knowing whether it is a topic or a queue.

Namespace:  Microsoft.ServiceBus.Messaging
Assembly:  Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)

[<AbstractClassAttribute>]
type MessageSender =  
    class
        inherit MessageClientEntity
    end

The MessageSender type exposes the following members.

  NameDescription
Public propertyBatchFlushIntervalGets the batch flush interval.
Protected propertyBatchingEnabledGets a value indicating whether the batching is enabled.
Public propertyIsClosed (Inherited from ClientEntity.)
Public propertyPathGets the path of the queue or topic relative to the MessagingFactory base address.
Public propertyRetryPolicy (Inherited from ClientEntity.)
Protected propertyThisLock (Inherited from ClientEntity.)
Top

  NameDescription
Public methodAbortPerforms abort functionality on the messaging entity. (Inherited from ClientEntity.)
Public methodBeginCloseBegins an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.)
Public methodBeginSendBegins an asynchronous request to send a brokered message.
Public methodBeginSendBatchBegins an asynchronous request to send a brokered message by batch.
Public methodCloseSends a cleanup message to Service Bus to signal the completion of the usage of an entity. (Inherited from ClientEntity.)
Public methodCloseAsyncSends a cleanup message asynchronously to Service Bus to signal the completion of the usage of an entity. (Inherited from ClientEntity.)
Public methodEndCloseFinishes an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.)
Public methodEndSendEnds an asynchronous request to send a message.
Public methodEndSendBatchEnds an asynchronous request to send a message by batch.
Public methodEquals (Inherited from Object.)
Protected methodFaultFor internal use only. Do not inherit from this class. (Inherited from ClientEntity.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodOnAbort (Inherited from ClientEntity.)
Protected methodOnBeginCancelScheduledMessageRaises an event that starts the cancellation of the scheduled message.
Protected methodOnBeginClose (Inherited from ClientEntity.)
Protected methodOnBeginOpen (Inherited from ClientEntity.)
Protected methodOnBeginScheduleMessageRaises an event when scheduling a message.
Protected methodOnBeginSendAllows concrete implementations to define what should be done when sending messages. This method cannot be implemented in a concrete class by the user.
Protected methodOnBeginSendEventDataRaises an event when sending event data.
Protected methodOnClose (Inherited from ClientEntity.)
Protected methodOnClosed (Inherited from ClientEntity.)
Protected methodOnEndCancelScheduledMessageRaises an event when ending the cancellation of the scheduled message.
Protected methodOnEndClose (Inherited from ClientEntity.)
Protected methodOnEndOpen (Inherited from ClientEntity.)
Protected methodOnEndScheduleMessageRaises an event when ending the message schedule.
Protected methodOnEndSendExecutes the end send action. This method cannot be implemented in a concrete class by the user.
Protected methodOnEndSendEventDataExecutes the end send event data action.
Protected methodOnFaulted (Inherited from ClientEntity.)
Protected methodOnOpen (Inherited from ClientEntity.)
Protected methodOnOpened (Inherited from ClientEntity.)
Protected methodOnSendAllows concrete implementations to override (if needed) what should be done when sending messages in a synchronous manner.
Public methodSendSends the specified brokered message.
Public methodSendAsyncAsynchronously sends the specified brokered message.
Public methodSendBatchSends a set of brokered messages (for batch processing).
Public methodSendBatchAsyncAsynchronously sends a set of brokered messages (for batch processing).
Protected methodThrowIfClosed (Inherited from ClientEntity.)
Protected methodThrowIfDisposed (Inherited from ClientEntity.)
Protected methodThrowIfDisposedOrImmutable (Inherited from ClientEntity.)
Protected methodThrowIfDisposedOrNotOpen (Inherited from ClientEntity.)
Protected methodThrowIfFaulted (Inherited from ClientEntity.)
Public methodToString (Inherited from Object.)
Top

Note that the default message receive mode is PeekLock, which ensures reliable message receiving.

The following example sends messages to a queue.

Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty); 

MessagingFactory factory = MessagingFactory.Create(serviceUri, credentials); 

MessageSender myMessageSender = factory.CreateMessageSender(queueName); 

List<BrokeredMessage> messageList = new List<BrokeredMessage>();
messageList.Add(CreateIssueMessage("1", "Package lost"));
messageList.Add(CreateIssueMessage("2", "Package damaged"));
messageList.Add(CreateIssueMessage("3", "Package defective"));

foreach (BrokeredMessage message in messageList)
{
    myMessageSender.Send(message);
    Console.WriteLine(
    string.Format("Message sent: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>()));
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Instance members are also guaranteed to be thread safe.

Community-inhoud

Toevoegen
Weergeven:
© 2014 Microsoft