public Message Peek() { var message = _client.Peek(); return(message == null ? null : new Message( message.GetBody <Stream>(), message.SessionId, message.Label, message.Properties)); }
public void DeInit() { if (receiveClient != null) { while (receiveClient.Peek() != null) { Trace.TraceInformation("Cleaning message"); var brokeredMessage = receiveClient.Receive(); brokeredMessage.Complete(); } this.receiveClient.Close(); this.sendClient.Close(); } }
public void DeInit() { if (client != null) { while (client.Peek() != null) { Trace.TraceInformation("Cleaning message"); var brokeredMessage = client.Receive(); brokeredMessage.Complete(); } this.client.Close(); this.globalDescriptorClient.Close(); } }
// Read the first published message from service bus subscription public string ReadFirstPublishedMessage(string ServiceBusConnectionString, string TopicName, string SubscriptionName, ref long messageCount) { // Create service Bus namespace manager var namespaceManager = NamespaceManager.CreateFromConnectionString(ServiceBusConnectionString); // Get subscrition information of the topic var subscriptionDesc = namespaceManager.GetSubscription(TopicName, SubscriptionName); // Check number of published messages messageCount = subscriptionDesc.MessageCount; // Skip reading message if none exists if (messageCount != 0) { // Create service bus messageing factory Factory = MessagingFactory.CreateFromConnectionString(ServiceBusConnectionString); // Create subscription client for the topic SubscriptionClient mySubscriptionClient = Factory.CreateSubscriptionClient(TopicName, SubscriptionName); // Get first broker message from the subscription. // Use Peek function to keep the brokerd message in the subscription BrokeredMessage MessageReceived = mySubscriptionClient.Peek(); // Retrieve message body as a stream object Stream myMessage = MessageReceived.GetBody <Stream>(); // Convert the stream object into a byte array Byte[] ByteData = StreamToByteArray(myMessage); // Convert UTF8 encoded byte array into message text string strData = Encoding.UTF8.GetString(ByteData); // Clean up MessageReceived.Dispose(); mySubscriptionClient.Close(); return(strData); } return(""); }