/// <summary>
 /// Adds a rule to the current subscription to filter the messages reaching from topic to the subscription.
 /// </summary>
 ///
 /// <param name="description">The rule description that provides the rule to add.</param>
 /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
 ///
 /// <remarks>
 /// You can add rules to the subscription that decides which messages from the topic should reach the subscription.
 /// A default <see cref="TrueRuleFilter"/> rule named <see cref="RuleProperties.DefaultRuleName"/> is always added while creation of the Subscription.
 /// You can add multiple rules with distinct names to the same subscription.
 /// Multiple filters combine with each other using logical OR condition. i.e., If any filter succeeds, the message is passed on to the subscription.
 /// </remarks>
 ///
 /// <returns>A task instance that represents the asynchronous add rule operation.</returns>
 public override async Task AddRuleAsync(
     RuleProperties description,
     CancellationToken cancellationToken = default) =>
 await _retryPolicy.RunOperation(
     async (timeout) =>
     await AddRuleInternalAsync(
         description,
         timeout).ConfigureAwait(false),
     _connectionScope,
     cancellationToken).ConfigureAwait(false);
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="retryPolicy"></param>
        /// <param name="fromSequenceNumber"></param>
        /// <param name="messageCount"></param>
        /// <param name="sessionId"></param>
        /// <param name="receiveLinkName"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <IEnumerable <ServiceBusMessage> > PeekAsync(
            ServiceBusRetryPolicy retryPolicy,
            long?fromSequenceNumber,
            int messageCount       = 1,
            string sessionId       = null,
            string receiveLinkName = null,
            CancellationToken cancellationToken = default)
        {
            IEnumerable <ServiceBusMessage> messages = null;
            Task peekTask = retryPolicy.RunOperation(async(timeout) =>
            {
                messages = await PeekInternal(
                    retryPolicy,
                    fromSequenceNumber,
                    messageCount,
                    sessionId,
                    receiveLinkName,
                    timeout,
                    cancellationToken).ConfigureAwait(false);
            },
                                                     EntityName,
                                                     ConnectionScope,
                                                     cancellationToken);
            await peekTask.ConfigureAwait(false);

            return(messages);
        }
Example #3
0
        /// <summary>
        ///   Creates a size-constraint batch to which <see cref="ServiceBusMessage" /> may be added using a try-based pattern.  If a message would
        ///   exceed the maximum allowable size of the batch, the batch will not allow adding the message and signal that scenario using its
        ///   return value.
        ///
        ///   Because messages that would violate the size constraint cannot be added, publishing a batch will not trigger an exception when
        ///   attempting to send the message to the Queue/Topic.
        /// </summary>
        ///
        /// <param name="options">The set of options to consider when creating this batch.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>An <see cref="ServiceBusMessageBatch" /> with the requested <paramref name="options"/>.</returns>
        ///
        public override async ValueTask <TransportMessageBatch> CreateBatchAsync(
            CreateBatchOptions options,
            CancellationToken cancellationToken)
        {
            TransportMessageBatch messageBatch = null;
            Task createBatchTask = _retryPolicy.RunOperation(async(timeout) =>
            {
                messageBatch = await CreateBatchInternalAsync(
                    options,
                    timeout).ConfigureAwait(false);
            },
                                                             _connectionScope,
                                                             cancellationToken);
            await createBatchTask.ConfigureAwait(false);

            return(messageBatch);
        }
Example #4
0
        /// <summary>
        ///   Receives a batch of <see cref="ServiceBusMessage" /> from the Service Bus entity partition.
        /// </summary>
        ///
        /// <param name="maximumMessageCount">The maximum number of messages to receive in this batch.</param>
        /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param>
        ///
        /// <returns>The batch of <see cref="ServiceBusMessage" /> from the Service Bus entity partition this consumer is associated with.  If no events are present, an empty enumerable is returned.</returns>
        ///
        public override async Task <IEnumerable <ServiceBusMessage> > ReceiveAsync(
            int maximumMessageCount,
            CancellationToken cancellationToken)
        {
            IEnumerable <ServiceBusMessage> messages = null;
            Task receiveMessageTask = _retryPolicy.RunOperation(async(timeout) =>
            {
                messages = await ReceiveAsyncInternal(
                    maximumMessageCount,
                    timeout,
                    cancellationToken).ConfigureAwait(false);
            },
                                                                EntityName,
                                                                ConnectionScope,
                                                                cancellationToken);
            await receiveMessageTask.ConfigureAwait(false);

            return(messages);
        }
Example #5
0
        /// <summary>
        /// Get the session Id corresponding to this consumer
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <string> GetSessionId(CancellationToken cancellationToken = default)
        {
            if (!_isSessionReceiver)
            {
                return(null);
            }
            ReceivingAmqpLink openedLink = null;
            await _retryPolicy.RunOperation(
                async (timeout) =>
                openedLink = await ReceiveLink.GetOrCreateAsync(timeout).ConfigureAwait(false),
                EntityName,
                ConnectionScope,
                cancellationToken).ConfigureAwait(false);

            var source = (Source)openedLink.Settings.Source;

            source.FilterSet.TryGetValue <string>(AmqpClientConstants.SessionFilterName, out var sessionId);
            return(sessionId);
        }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sequenceNumber"></param>
 /// <param name="retryPolicy"></param>
 /// <param name="receiveLinkName"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public override async Task CancelScheduledMessageAsync(
     long sequenceNumber,
     ServiceBusRetryPolicy retryPolicy,
     string receiveLinkName = null,
     CancellationToken cancellationToken = default)
 {
     Task cancelMessageTask = retryPolicy.RunOperation(async(timeout) =>
     {
         await CancelScheduledMessageInternal(
             sequenceNumber,
             retryPolicy,
             receiveLinkName,
             timeout,
             cancellationToken).ConfigureAwait(false);
     },
                                                       EntityName,
                                                       ConnectionScope,
                                                       cancellationToken);
     await cancelMessageTask.ConfigureAwait(false);
 }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="retryPolicy"></param>
        /// <param name="receiveLinkName"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override async Task <long> ScheduleMessageAsync(
            ServiceBusMessage message,
            ServiceBusRetryPolicy retryPolicy,
            string receiveLinkName = null,
            CancellationToken cancellationToken = default)
        {
            long sequenceNumber = 0;
            Task scheduleTask   = retryPolicy.RunOperation(async(timeout) =>
            {
                sequenceNumber = await ScheduleMessageInternal(
                    message,
                    retryPolicy,
                    receiveLinkName,
                    timeout,
                    cancellationToken).ConfigureAwait(false);
            },
                                                           EntityName,
                                                           ConnectionScope,
                                                           cancellationToken);
            await scheduleTask.ConfigureAwait(false);

            return(sequenceNumber);
        }