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.
System.Object
Microsoft.ServiceBus.Messaging.MessageClientEntity
Microsoft.ServiceBus.Messaging.MessageSender
Microsoft.ServiceBus.Messaging.MessageClientEntity
Microsoft.ServiceBus.Messaging.MessageSender
Namespace: Microsoft.ServiceBus.Messaging
Assembly: Microsoft.ServiceBus (in Microsoft.ServiceBus.dll)
The MessageSender type exposes the following members.
| Name | Description | |
|---|---|---|
|
BatchFlushInterval | Gets the batch flush interval. |
|
BatchingEnabled | Gets a value indicating whether the batching is enabled. |
|
IsClosed | Gets or sets a value that indicates whether the message client entity is closed. (Inherited from MessageClientEntity.) |
|
Path | Gets the path of the queue or topic relative to the MessagingFactory base address. |
| Name | Description | |
|---|---|---|
|
Abort | Aborts the message client entity and puts its status into a closing state. (Inherited from MessageClientEntity.) |
|
BeginClose | Begins an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.) |
|
BeginSend | Begins an asynchronous request to send a brokered message. |
|
Close | Closes the message client entity and puts its status into a closed state. (Inherited from MessageClientEntity.) |
|
EndClose | Finishes an asynchronous operation to close the message client entity. (Inherited from MessageClientEntity.) |
|
EndSend | Ends an asynchronous request to send a message. |
|
Equals | (Inherited from Object.) |
|
Fault | Puts the message client entity into a faulted state. (Inherited from MessageClientEntity.) |
|
Finalize | (Inherited from Object.) |
|
GetHashCode | (Inherited from Object.) |
|
GetType | (Inherited from Object.) |
|
MemberwiseClone | (Inherited from Object.) |
|
OnAbort | Executes upon calling the Abort operation. (Inherited from MessageClientEntity.) |
|
OnBeginClose | Executes upon calling the BeginClose operation. (Inherited from MessageClientEntity.) |
|
OnBeginOpen | Executes upon calling the operation to begin to open the message client entity. (Inherited from MessageClientEntity.) |
|
OnBeginSend | Allows concrete implementations to define what should be done when sending messages. This method cannot be implemented in a concrete class by the user. |
|
OnClose | Executes upon calling the Close operation. (Inherited from MessageClientEntity.) |
|
OnClosed | Occurs when the message client entity is transitioned into a closing state. (Inherited from MessageClientEntity.) |
|
OnEndClose | Executes upon calling the EndClose operation. (Inherited from MessageClientEntity.) |
|
OnEndOpen | Executes upon calling the operation to end to open the message client entity. (Inherited from MessageClientEntity.) |
|
OnEndSend | Executes the end send action. This method cannot be implemented in a concrete class by the user. |
|
OnFaulted | Executes upon calling the Fault operation. (Inherited from MessageClientEntity.) |
|
OnOpen | Executes upon calling the operation to open the message client entity. (Inherited from MessageClientEntity.) |
|
OnOpened | Executes when the message client entity is opened. (Inherited from MessageClientEntity.) |
|
OnSend | Allows concrete implementations to override (if needed) what should be done when sending messages in a synchronous manner. |
|
Send | Sends the specified brokered message. |
|
ThrowIfClosed | Throws an exception if the message client entity is closed. (Inherited from MessageClientEntity.) |
|
ThrowIfDisposed | Throws an exception if the message client entity is disposed. (Inherited from MessageClientEntity.) |
|
ThrowIfDisposedOrImmutable | Throws an exception if the client is disposed or immutable. (Inherited from MessageClientEntity.) |
|
ThrowIfDisposedOrNotOpen | Throws an exception if the client is disposed or not open. (Inherited from MessageClientEntity.) |
|
ThrowIfFaulted | Throws an exception if the client is faulted. (Inherited from MessageClientEntity.) |
|
ToString | (Inherited from Object.) |
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>())); }