public static IObservable<IBusMessage<T>> CreateObervableBatch<T>(this SubscriptionClient client, int messageCount, CancellationToken cancellationToken)
        {
            Func<IObserver<ServiceBusBusMessage<T>>, Task> t = async (observer) =>  {
                try
                {
                    while (!client.IsClosed)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        var messages = await client.ReceiveBatchAsync(messageCount);
                        if (messages == null)
                        {
                            observer.OnCompleted();
                            break;
                        }

                        foreach (var message in messages)
                        {
                            observer.OnNext(new ServiceBusBusMessage<T>(message));
                        }
                    }
                }
                catch (Exception e)
                {
                    observer.OnError(e);
                }
            };

            return Observable
              .Create<ServiceBusBusMessage<T>>(t)
              .Publish()
              .RefCount();
        }
Example #2
0
        public async Task <IEnumerable <IMessage <T> > > ReceiveBatchAsAsync(int batchSize)
        {
            return(await _executionPolicy.ExecuteAsync(async() =>
            {
                try
                {
                    if (!_clientOpen)
                    {
                        OpenClient();
                    }

                    var messages = new List <IMessage <T> >();

                    var brokeredMessages = await _client.ReceiveBatchAsync(batchSize);

                    foreach (var brokeredMessage in brokeredMessages)
                    {
                        var message = await DeserialiseAzureBrokeredMessage(brokeredMessage);

                        if (message != null)
                        {
                            messages.Add(message);
                        }
                    }

                    return messages;
                }
                catch (SessionLockLostException)
                {
                    RefreshClient();
                    throw;
                }
            }));
        }
Example #3
0
        /// <summary>
        /// Retrieves the given number of messages
        /// </summary>
        /// <param name="numberOfMessages">Number of messages to retrieve</param>
        /// <param name="seconds">Waiting time</param>
        /// <returns>The messages retrieved</returns>
        public async Task<IEnumerable<IBrokeredMessage>> RetrieveAsync(
            int numberOfMessages = 1, int seconds = 1)
        {
            var messages = await _client.ReceiveBatchAsync(
                numberOfMessages, new TimeSpan(0, 0, seconds));

            return Transform(messages);
        }
        public async Task <ICollection <BrokeredMessage> > GetMessagesAsync(string subscriptionName)
        {
            if (string.IsNullOrEmpty(subscriptionName))
            {
                throw new DSWException(SUBSCRIPTION_NOT_INITIALIZE, null, DSWExceptionCode.SS_Mapper);
            }
            SubscriptionClient client = SubscriptionClient.Create(TopicName, subscriptionName, ReceiveMode.ReceiveAndDelete);

            return((await client.ReceiveBatchAsync(1)).ToList());
        }
        public async Task when_forwarding_multiple_messages_all_lock_tokens_are_returned_and_the_messages_are_forwarded()
        {
            var forwarder         = new TopicMessageForwarder(topicClient, null);
            var messagesToForward = new List <BrokeredMessage>();

            messagesToForward.Add(await MessageFactory.CreateMessageWithJsonBody());
            messagesToForward.Add(await MessageFactory.CreateMessageWithJsonBody());
            await topicClient.SendBatchAsync(messagesToForward);

            var receivedMessages = await subscriptionClient.ReceiveBatchAsync(100);

            returnedLockTokens = await forwarder.ForwardMessages(receivedMessages);

            forwardedMessages = await subscriptionClient.ReceiveBatchAsync(100);

            Assert.That(returnedLockTokens.Count(), Is.EqualTo(2));
            CollectionAssert.AllItemsAreUnique(returnedLockTokens);
            Assert.That(forwardedMessages.Count(), Is.EqualTo(2));
        }
Example #6
0
 private Task <IEnumerable <BrokeredMessage> > ReceiveBatchAsync(int messageCount, TimeSpan serverWaitTime)
 {
     return(_subscriptionClient.ReceiveBatchAsync(messageCount, serverWaitTime));
 }
Example #7
0
        public async Task <IEnumerable <BrokeredMessage> > ReceiveAsync(string connectionString, string topic, string subscription, ReceiveMode receiveMode, int batchSize, int timeoutMilliSeconds)
        {
            SubscriptionClient subscribeClient = ServiceBusConnectionsFactory.GetSubscriptionClient(connectionString, topic, subscription);

            return(await subscribeClient.ReceiveBatchAsync(1000, new TimeSpan(0, 0, 0, 0, timeoutMilliSeconds)));
        }
Example #8
0
 public Task <IEnumerable <BrokeredMessage> > ReceieveMessages(int batchSize)
 {
     return(client.ReceiveBatchAsync(batchSize));
 }
Example #9
0
 public Task <IEnumerable <BrokeredMessage> > ReceiveBatchAsync(int messageCount, TimeSpan serverWaitTime)
 => _client.ReceiveBatchAsync(messageCount, serverWaitTime);