public override TransportReceiver CreateReceiver(string entityPath, ServiceBusRetryPolicy retryPolicy, ServiceBusReceiveMode receiveMode, uint prefetchCount, string identifier, string sessionId, bool isSessionReceiver, bool isProcessor, CancellationToken cancellationToken) { throw new NotImplementedException(); }
/// <summary> /// Creates a receiver strongly aligned with the active protocol and transport, responsible /// for reading <see cref="ServiceBusMessage" /> from a specific Service Bus entity. /// </summary> /// <param name="entityPath">The entity path to receive from.</param> /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> /// <param name="receiveMode">The <see cref="ServiceBusReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param> /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested. If <c>null</c> a default will be used.</param> /// <param name="identifier">The identifier for the sender.</param> /// <param name="sessionId">The session ID to receive messages for.</param> /// <param name="isSessionReceiver">Whether or not this is a sessionful receiver link.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the /// open link operation. Only applicable for session receivers.</param> /// /// <returns>A <see cref="TransportReceiver" /> configured in the requested manner.</returns> public override TransportReceiver CreateReceiver( string entityPath, ServiceBusRetryPolicy retryPolicy, ServiceBusReceiveMode receiveMode, uint prefetchCount, string identifier, string sessionId, bool isSessionReceiver, CancellationToken cancellationToken) { Argument.AssertNotDisposed(_closed, nameof(AmqpClient)); return(new AmqpReceiver ( entityPath, receiveMode, prefetchCount, ConnectionScope, retryPolicy, identifier, sessionId, isSessionReceiver, cancellationToken )); }
/// <summary> /// Creates a receiver strongly aligned with the active protocol and transport, responsible /// for reading <see cref="ServiceBusMessage" /> from a specific Service Bus entity. /// </summary> /// <param name="entityPath"></param> /// /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> /// <param name="receiveMode">The <see cref="ServiceBusReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param> /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested. If <c>null</c> a default will be used.</param> /// <param name="identifier"></param> /// <param name="sessionId"></param> /// <param name="isSessionReceiver"></param> /// /// <returns>A <see cref="TransportReceiver" /> configured in the requested manner.</returns> /// public abstract TransportReceiver CreateReceiver( string entityPath, ServiceBusRetryPolicy retryPolicy, ServiceBusReceiveMode receiveMode, uint prefetchCount, string identifier, string sessionId, bool isSessionReceiver);
public ServiceBusDeadLetterQueue(string connectionString, string queue, ServiceBusReceiveMode receiveMode = ServiceBusReceiveMode.PeekLock) : base(connectionString, queue, receiveMode, false) { // For picking up the message from a DLQ, we make a receiver just like for a // regular queue. We could also use QueueClient and a registered handler here. // The required path is constructed with the EntityNameHelper.FormatDeadLetterPath() // helper method, and always follows the pattern "{entity}/$DeadLetterQueue", // meaning that for a queue "Q1", the path is "Q1/$DeadLetterQueue" and for a // topic "T1" and subscription "S1", the path is "T1/Subscriptions/S1/$DeadLetterQueue" this.SubQueue = SubQueue.DeadLetter; }
public ServiceBusQueue(string connectionString, string queueName, ServiceBusReceiveMode receiveMode = ServiceBusReceiveMode.PeekLock, bool createQueueIfItDoesNotExist = true) : base(connectionString) { this.connectionString = connectionString; this.queueName = queueName; this.receiveMode = receiveMode; this.SubQueue = SubQueue.None; busAdmin = new ServiceBusAdministrationClient(this.connectionString); if (createQueueIfItDoesNotExist && !busAdmin.QueueExistsAsync(queueName).Result.Value) { busAdmin.CreateQueueAsync(queueName).Wait(); } }
internal virtual TransportReceiver CreateTransportReceiver( string entityPath, ServiceBusRetryPolicy retryPolicy, ServiceBusReceiveMode receiveMode, uint prefetchCount, string identifier, string sessionId, bool isSessionReceiver) => _innerClient.CreateReceiver( entityPath, retryPolicy, receiveMode, prefetchCount, identifier, sessionId, isSessionReceiver);
/// <summary> /// Initializes an Instance of <see cref="AzureServiceBusConsumer"/> /// </summary> /// <param name="topicName">The name of the Topic.</param> /// <param name="subscriptionName">The name of the Subscription on the Topic.</param> /// <param name="messageProducerSync">An instance of the Messaging Producer used for Requeue.</param> /// <param name="administrationClientWrapper">An Instance of Administration Client Wrapper.</param> /// <param name="serviceBusReceiverProvider">An Instance of <see cref="ServiceBusReceiverProvider"/>.</param> /// <param name="batchSize">How many messages to receive at a time.</param> /// <param name="receiveMode">The mode in which to Receive.</param> /// <param name="makeChannels">The mode in which to make Channels.</param> /// <param name="subscriptionConfiguration">The configuration options for the subscriptions.</param> public AzureServiceBusConsumer(string topicName, string subscriptionName, IAmAMessageProducerSync messageProducerSync, IAdministrationClientWrapper administrationClientWrapper, IServiceBusReceiverProvider serviceBusReceiverProvider, int batchSize = 10, ServiceBusReceiveMode receiveMode = ServiceBusReceiveMode.ReceiveAndDelete, OnMissingChannel makeChannels = OnMissingChannel.Create, AzureServiceBusSubscriptionConfiguration subscriptionConfiguration = default) { _subscriptionName = subscriptionName; _topicName = topicName; _messageProducerSync = messageProducerSync; _administrationClientWrapper = administrationClientWrapper; _serviceBusReceiverProvider = serviceBusReceiverProvider; _batchSize = batchSize; _makeChannel = makeChannels; _subscriptionConfiguration = subscriptionConfiguration ?? new AzureServiceBusSubscriptionConfiguration(); _receiveMode = receiveMode; GetMessageReceiverProvider(); }
internal virtual TransportReceiver CreateTransportReceiver( string entityPath, ServiceBusRetryPolicy retryPolicy, ServiceBusReceiveMode receiveMode, uint prefetchCount, string identifier, string sessionId, bool isSessionReceiver, bool isProcessor, CancellationToken cancellationToken) => InnerClient.CreateReceiver( entityPath, retryPolicy, receiveMode, prefetchCount, identifier, sessionId, isSessionReceiver, isProcessor, cancellationToken);
public ServiceBusQueue(string connectionString, string topicName, string subscription, ServiceBusReceiveMode receiveMode = ServiceBusReceiveMode.PeekLock, bool createQueueIfItDoesNotExist = true) : base(connectionString) { this.connectionString = connectionString; this.queueName = topicName; this.topicName = topicName; this.subscription = subscription; this.receiveMode = receiveMode; this.SubQueue = SubQueue.None; busAdmin = new ServiceBusAdministrationClient(this.connectionString); if (createQueueIfItDoesNotExist && !busAdmin.TopicExistsAsync(topicName).Result.Value) { busAdmin.CreateTopicAsync(topicName).Wait(); } if (createQueueIfItDoesNotExist && !string.IsNullOrEmpty(subscription) && !busAdmin.SubscriptionExistsAsync(topicName, subscription).Result.Value) { busAdmin.CreateSubscriptionAsync(topicName, subscription).Wait(); } }
/// <summary> /// Opens an AMQP link for use with receiver operations. /// </summary> /// <param name="entityPath">The entity path to receive from.</param> /// <param name="timeout">The timeout to apply when creating the link.</param> /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested.</param> /// <param name="receiveMode">The <see cref="ServiceBusReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param> /// <param name="sessionId">The session to connect to.</param> /// <param name="isSessionReceiver">Whether or not this is a sessionful receiver.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>A link for use with consumer operations.</returns> /// public virtual async Task <ReceivingAmqpLink> OpenReceiverLinkAsync( string entityPath, TimeSpan timeout, uint prefetchCount, ServiceBusReceiveMode receiveMode, string sessionId, bool isSessionReceiver, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); var stopWatch = ValueStopwatch.StartNew(); var receiverEndpoint = new Uri(ServiceEndpoint, entityPath); var connection = await ActiveConnection.GetOrCreateAsync(timeout).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); ReceivingAmqpLink link = await CreateReceivingLinkAsync( entityPath, connection, receiverEndpoint, timeout.CalculateRemaining(stopWatch.GetElapsedTime()), prefetchCount, receiveMode, sessionId, isSessionReceiver, cancellationToken ).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); await OpenAmqpObjectAsync(link, timeout.CalculateRemaining(stopWatch.GetElapsedTime())).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); return(link); }
public IServiceBusReceiverWrapper Get(string topicName, string subscriptionName, ServiceBusReceiveMode receiveMode) { var messageReceiver = _client.CreateReceiver(topicName, subscriptionName, new ServiceBusReceiverOptions() { ReceiveMode = receiveMode, }); return(new ServiceBusReceiverWrapper(messageReceiver)); }
/// <summary> /// Creates an AMQP link for use with receiving operations. /// </summary> /// <param name="entityPath">The entity path to receive from.</param> /// <param name="connection">The active and opened AMQP connection to use for this link.</param> /// <param name="endpoint">The fully qualified endpoint to open the link for.</param> /// <param name="prefetchCount">Controls the number of events received and queued locally without regard to whether an operation was requested.</param> /// <param name="receiveMode">The <see cref="ServiceBusReceiveMode"/> used to specify how messages are received. Defaults to PeekLock mode.</param> /// <param name="sessionId">The session to receive from.</param> /// <param name="isSessionReceiver">Whether or not this is a sessionful receiver.</param> /// <param name="timeout">The timeout to apply when creating the link.</param> /// <param name="cancellationToken">An optional <see cref="CancellationToken"/> instance to signal the request to cancel the operation.</param> /// /// <returns>A link for use for operations related to receiving events.</returns> protected virtual async Task <ReceivingAmqpLink> CreateReceivingLinkAsync( string entityPath, AmqpConnection connection, Uri endpoint, TimeSpan timeout, uint prefetchCount, ServiceBusReceiveMode receiveMode, string sessionId, bool isSessionReceiver, CancellationToken cancellationToken) { Argument.AssertNotDisposed(IsDisposed, nameof(AmqpConnectionScope)); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); var session = default(AmqpSession); var stopWatch = ValueStopwatch.StartNew(); try { // Perform the initial authorization for the link. string[] authClaims = new string[] { ServiceBusClaim.Send }; var audience = new[] { endpoint.AbsoluteUri }; DateTime authExpirationUtc = await RequestAuthorizationUsingCbsAsync( connection, TokenProvider, endpoint, audience, authClaims, timeout.CalculateRemaining(stopWatch.GetElapsedTime())).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); // Create and open the AMQP session associated with the link. var sessionSettings = new AmqpSessionSettings { Properties = new Fields() }; // This is the maximum number of unsettled transfers across all receive links on this session. // This will allow the session to accept unlimited number of transfers, even if the receiver(s) // are not settling any of the deliveries. sessionSettings.IncomingWindow = uint.MaxValue; session = connection.CreateSession(sessionSettings); await OpenAmqpObjectAsync(session, timeout).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested <TaskCanceledException>(); var filters = new FilterSet(); // even if supplied sessionId is null, we need to add the Session filter if it is a session receiver if (isSessionReceiver) { filters.Add(AmqpClientConstants.SessionFilterName, sessionId); } var linkSettings = new AmqpLinkSettings { Role = true, TotalLinkCredit = prefetchCount, AutoSendFlow = prefetchCount > 0, SettleType = (receiveMode == ServiceBusReceiveMode.PeekLock) ? SettleMode.SettleOnDispose : SettleMode.SettleOnSend, Source = new Source { Address = endpoint.AbsolutePath, FilterSet = filters }, Target = new Target { Address = Guid.NewGuid().ToString() } }; var link = new ReceivingAmqpLink(linkSettings); linkSettings.LinkName = $"{connection.Settings.ContainerId};{connection.Identifier}:{session.Identifier}:{link.Identifier}:{linkSettings.Source.ToString()}"; link.AttachTo(session); // Configure refresh for authorization of the link. var refreshTimer = default(Timer); TimerCallback refreshHandler = CreateAuthorizationRefreshHandler ( entityPath, connection, link, TokenProvider, endpoint, audience, authClaims, AuthorizationRefreshTimeout, () => (ActiveLinks.ContainsKey(link) ? refreshTimer : null) ); refreshTimer = new Timer(refreshHandler, null, CalculateLinkAuthorizationRefreshInterval(authExpirationUtc), Timeout.InfiniteTimeSpan); // Track the link before returning it, so that it can be managed with the scope. BeginTrackingLinkAsActive(entityPath, link, refreshTimer); return(link); } catch (Exception exception) { // Aborting the session will perform any necessary cleanup of // the associated link as well. session?.Abort(); ExceptionDispatchInfo.Capture(AmqpExceptionHelper.TranslateException( exception, null, session.GetInnerException(), connection.IsClosing())) .Throw(); throw; // will never be reached } }
public ServiceBusDeadLetterQueue(string connectionString, string topic, string subscription, ServiceBusReceiveMode receiveMode = ServiceBusReceiveMode.PeekLock) : base(connectionString, topic, subscription, receiveMode, false) { this.SubQueue = SubQueue.DeadLetter; }