コード例 #1
0
        /// <summary>
        /// Creates a new Azure Service Bus client that facilitates receive operations.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message that the client handles.
        /// </typeparam>
        /// <param name="entityType">
        /// The type of the entity.
        /// </param>
        /// <returns>
        /// A new Azure Service Bus client that facilitates receive operations.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="MessageSubscriptionException">
        /// An exception was raised while creating the client.
        /// </exception>
        public IReceiverClient CreateReceiveClient <TMessage>(MessagingEntityType entityType)
            where TMessage : class
        {
            switch (entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType)).TargetArgument)
            {
            case MessagingEntityType.Queue:

                try
                {
                    return(CreateQueueClient <TMessage>());
                }
                catch (Exception exception)
                {
                    throw new MessageSubscriptionException(typeof(TMessage), exception);
                }

            case MessagingEntityType.Topic:

                try
                {
                    return(CreateSubscriptionClient <TMessage>());
                }
                catch (Exception exception)
                {
                    throw new MessageSubscriptionException(typeof(TMessage), exception);
                }

            default:

                throw new InvalidOperationException($"The specified entity type, {entityType}, is not supported.");
            }
        }
コード例 #2
0
 internal HeartbeatScheduleItem(Int32 intervalInSeconds, MessagingEntityType entityType, String label)
     : base()
 {
     EntityType        = entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType));
     IntervalInSeconds = intervalInSeconds.RejectIf().IsLessThanOrEqualTo(0, nameof(intervalInSeconds));
     Label             = label;
 }
コード例 #3
0
 public void AmqpSendLinkCreateStart(string clientId, MessagingEntityType entityType, string entityPath)
 {
     if (this.IsEnabled())
     {
         this.AmqpSendLinkCreateStart(clientId, entityType.ToString(), entityPath);
     }
 }
コード例 #4
0
 public MessageTypeMessagingEntityMappingDetails(Type messageType, string path, MessagingEntityType messagingEntityType, MessagingEntityCreationOptions creationOptions, MessageReceiveMode receiveMode)
 {
     _messageType         = messageType;
     _path                = path;
     _messagingEntityType = messagingEntityType;
     _creationOptions     = creationOptions;
     _receiveMode         = receiveMode;
 }
コード例 #5
0
 internal AmqpMessageSender(string entityName, MessagingEntityType entityType, ServiceBusConnection serviceBusConnection, ICbsTokenProvider cbsTokenProvider)
     : base(serviceBusConnection.OperationTimeout)
 {
     this.Path                 = entityName;
     this.EntityType           = entityType;
     this.ServiceBusConnection = serviceBusConnection;
     this.CbsTokenProvider     = cbsTokenProvider;
     this.SendLinkManager      = new FaultTolerantAmqpObject <SendingAmqpLink>(this.CreateLinkAsync, this.CloseSession);
 }
コード例 #6
0
 public AmqpSubscriptionClient(
     ServiceBusConnection servicebusConnection,
     string entityPath,
     MessagingEntityType entityType,
     RetryPolicy retryPolicy,
     ReceiveMode mode = ReceiveMode.ReceiveAndDelete)
     : base(servicebusConnection, entityPath, entityType, retryPolicy, mode)
 {
 }
コード例 #7
0
 public GetMessageSessionsAsyncResult(SbmpMessagingFactory messagingFactory, string entityName, DateTime lastUpdatedTime, SbmpMessageCreator messageCreator, RetryPolicy retryPolicy, MessagingEntityType entityType, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state)
 {
     this.lastUpdatedTime  = lastUpdatedTime;
     this.MessagingFactory = messagingFactory;
     this.messageCreator   = messageCreator;
     this.entityName       = entityName;
     this.messageSessions  = new List <MessageSession>();
     this.entityType       = entityType;
     this.sessionsPageSize = 100;
     this.retryPolicy      = retryPolicy;
     base.Start();
 }
コード例 #8
0
        /// <summary>
        /// Adds support for the specified message type.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message for which support is added.
        /// </typeparam>
        /// <param name="entityType">
        /// The targeted entity type.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <typeparamref name="TMessage" /> was already added.
        /// </exception>
        public void AddSubscriber <TMessage>(MessagingEntityType entityType)
            where TMessage : class, IMessage
        {
            var messageType = typeof(TMessage);

            if (SupportedMessageTypesReference.Contains(messageType))
            {
                throw new InvalidOperationException($"Support for the type {messageType.FullName} was already added.");
            }

            SupportedMessageTypesReference.Add(messageType);
            RootDependencyScope.Resolve <IMessageSubscriptionClient>().RegisterHandler <TMessage>((message) => HandleMessage(message), entityType);
        }
コード例 #9
0
 public AmqpMessageReceiver(string entityName, MessagingEntityType entityType, ReceiveMode mode, int prefetchCount, ServiceBusConnection serviceBusConnection, ICbsTokenProvider cbsTokenProvider, string sessionId, bool isSessionReceiver = false)
     : base(mode, serviceBusConnection.OperationTimeout)
 {
     this.entityName                    = entityName;
     this.EntityType                    = entityType;
     this.ServiceBusConnection          = serviceBusConnection;
     this.CbsTokenProvider              = cbsTokenProvider;
     this.sessionId                     = sessionId;
     this.isSessionReceiver             = isSessionReceiver;
     this.ReceiveLinkManager            = new FaultTolerantAmqpObject <ReceivingAmqpLink>(this.CreateLinkAsync, this.CloseSession);
     this.RequestResponseLinkManager    = new FaultTolerantAmqpObject <RequestResponseAmqpLink>(this.CreateRequestResponseLinkAsync, this.CloseRequestResponseSession);
     this.requestResponseLockedMessages = new ConcurrentExpiringSet <Guid>();
     this.PrefetchCount                 = prefetchCount;
 }
コード例 #10
0
 internal AmqpClient(
     ServiceBusConnection servicebusConnection,
     string entityPath,
     MessagingEntityType entityType,
     RetryPolicy retryPolicy,
     ReceiveMode mode = ReceiveMode.ReceiveAndDelete)
 {
     this.ServiceBusConnection = servicebusConnection;
     this.EntityPath           = entityPath;
     this.MessagingEntityType  = entityType;
     this.ReceiveMode          = mode;
     this.TokenProvider        = TokenProvider.CreateSharedAccessSignatureTokenProvider(
         servicebusConnection.SasKeyName,
         servicebusConnection.SasKey);
     this.CbsTokenProvider = new TokenProviderAdapter(this.TokenProvider, servicebusConnection.OperationTimeout);
     this.RetryPolicy      = retryPolicy;
 }
コード例 #11
0
        private static String GetEntityPath <TMessage>(MessagingEntityType entityType)
            where TMessage : class
        {
            switch (entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType)).TargetArgument)
            {
            case MessagingEntityType.Queue:

                return(AzureServiceBusClientFactory.GetQueuePath <TMessage>());

            case MessagingEntityType.Topic:

                return(AzureServiceBusClientFactory.GetTopicPath <TMessage>());

            default:

                throw new InvalidOperationException($"The specified entity type, {entityType}, is not supported.");
            }
        }
コード例 #12
0
        /// <summary>
        /// Gets a shared, managed <see cref="IReceiverClient" /> instance.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message that the client handles.
        /// </typeparam>
        /// <param name="entityType">
        /// The type of the entity.
        /// </param>
        /// <returns>
        /// The managed <see cref="IReceiverClient" /> instance.
        /// </returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="MessageSubscriptionException">
        /// An exception was raised while creating the client.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The object is disposed.
        /// </exception>
        public IReceiverClient GetReceiveClient <TMessage>(MessagingEntityType entityType)
            where TMessage : class
        {
            var entityPath = GetEntityPath <TMessage>(entityType);

            using (var controlToken = StateControl.Enter())
            {
                RejectIfDisposed();

                if (ReceiveClientDictionary.TryGetValue(entityPath, out var client))
                {
                    return(client);
                }

                client = ClientFactory.CreateReceiveClient <TMessage>(entityType);
                ReceiveClientDictionary.Add(entityPath, client);
                return(client);
            }
        }
コード例 #13
0
 public AmqpSessionClient(
     string clientId,
     string entityPath,
     MessagingEntityType entityType,
     ReceiveMode receiveMode,
     int prefetchCount,
     ServiceBusConnection serviceBusConnection,
     ICbsTokenProvider cbsTokenProvider,
     RetryPolicy retryPolicy)
 {
     this.ClientId             = clientId;
     this.EntityPath           = entityPath;
     this.EntityType           = entityType;
     this.ReceiveMode          = receiveMode;
     this.PrefetchCount        = prefetchCount;
     this.ServiceBusConnection = serviceBusConnection;
     this.CbsTokenProvider     = cbsTokenProvider;
     this.RetryPolicy          = retryPolicy;
 }
コード例 #14
0
        /// <summary>
        /// Asynchronously publishes the specified message to a bus.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message to publish.
        /// </typeparam>
        /// <param name="message">
        /// The message to publish.
        /// </param>
        /// <param name="entityType">
        /// The targeted entity type.
        /// </param>
        /// <returns>
        /// A task representing the asynchronous operation.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="message" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="MessagePublishingException">
        /// An exception was raised while attempting to publish <paramref name="message" />.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The object is disposed.
        /// </exception>
        public async Task PublishAsync <TMessage>(TMessage message, MessagingEntityType entityType)
            where TMessage : class, IMessage
        {
            message    = message.RejectIf().IsNull(nameof(message)).TargetArgument;
            entityType = entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType));

            try
            {
                using (var controlToken = StateControl.Enter())
                {
                    RejectIfDisposed();
                    await PublishAsync(message, entityType, controlToken).ConfigureAwait(false);
                }
            }
            catch (MessagePublishingException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new MessagePublishingException(typeof(TMessage), exception);
            }
        }
コード例 #15
0
        /// <summary>
        /// Registers the specified message handler with the bus.
        /// </summary>
        /// <typeparam name="TMessage">
        /// The type of the message.
        /// </typeparam>
        /// <param name="messageHandler">
        /// An action that handles a message.
        /// </param>
        /// <param name="entityType">
        /// The targeted entity type.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="messageHandler" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
        /// </exception>
        /// <exception cref="MessageSubscriptionException">
        /// An exception was raised while attempting to register <paramref name="messageHandler" />.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// The object is disposed.
        /// </exception>
        public void RegisterHandler <TMessage>(Action <TMessage> messageHandler, MessagingEntityType entityType)
            where TMessage : class, IMessage
        {
            messageHandler = messageHandler.RejectIf().IsNull(nameof(messageHandler)).TargetArgument;
            entityType     = entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType)).TargetArgument;

            try
            {
                using (var controlToken = StateControl.Enter())
                {
                    RejectIfDisposed();
                    RegisterHandler(messageHandler, entityType, controlToken);
                }
            }
            catch (MessageSubscriptionException)
            {
                throw;
            }
            catch (Exception exception)
            {
                throw new MessageSubscriptionException(typeof(TMessage), exception);
            }
        }
コード例 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageHandler{TMessage}" /> class.
 /// </summary>
 /// <param name="mediator">
 /// A processing intermediary that is used to process sub-commands.
 /// </param>
 /// <param name="role">
 /// The role of the handler.
 /// </param>
 /// <param name="entityType">
 /// The targeted entity type.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="mediator" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="role" /> is equal to <see cref="MessageHandlerRole.Unspecified" /> -or- <paramref name="entityType" /> is
 /// equal to <see cref="MessagingEntityType.Unspecified" />.
 /// </exception>
 protected MessageHandler(ICommandMediator mediator, MessageHandlerRole role, MessagingEntityType entityType)
     : base(mediator)
 {
     EntityType = entityType.RejectIf().IsEqualToValue(MessagingEntityType.Unspecified, nameof(entityType));
     Role       = role.RejectIf().IsEqualToValue(MessageHandlerRole.Unspecified, nameof(role));
 }
コード例 #17
0
 public MessagingEntityAlreadyExistsException(string path, MessagingEntityType messagingEntityType)
     : base(string.Format("A messaging entity with a path of \"{0}\" of type {1} already exists. To ensure intent and keep your data safe the framwork will not recreate it as temporary unless explicitly configured to do so. You can change the configuration to explicitly enable deletion of existing temporary entities or manually delete the entity.", path, messagingEntityType))
 {
     Path = path;
     MessagingEntityType = messagingEntityType;
 }
コード例 #18
0
 public MessagingEntityAlreadyExistsException(string path, MessagingEntityType messagingEntityType)
     : base(string.Format("A messaging entity with a path of \"{0}\" of type {1} already exists. To ensure intent and keep your data safe the framwork will not recreate it as temporary unless explicitly configured to do so. You can change the configuration to explicitly enable deletion of existing temporary entities or manually delete the entity.", path, messagingEntityType))
 {
     Path = path;
     MessagingEntityType = messagingEntityType;
 }
コード例 #19
0
 public MappingAlreadyExistsForMessageTypeException(Type messageType, MessagingEntityType entityType)
     : base(string.Format("A mapping already exists for message type {0} for entity type {1}", messageType.Name, entityType))
 {
     MessageType = messageType;
     EntityType  = entityType;
 }
コード例 #20
0
 public MessagingEntityDoesNotAlreadyExistException(string path, MessagingEntityType messagingEntityType)
     : base(string.Format("A messaging entity with a path of \"{0}\" of type {1} does not exist and was not configured to be created automatically.", path, messagingEntityType))
 {
     Path = path;
     MessagingEntityType = messagingEntityType;
 }
コード例 #21
0
 public void AmqpReceiveLinkCreateStart(string clientId, bool isRequestResponseLink, MessagingEntityType entityType, string entityPath)
 {
     if (this.IsEnabled())
     {
         this.AmqpReceiveLinkCreateStart(clientId, isRequestResponseLink.ToString(), entityType.ToString(), entityPath);
     }
 }
コード例 #22
0
 /// <summary>
 /// Adds the specified heartbeat schedule item to the schedule.
 /// </summary>
 /// <typeparam name="TMessage">
 /// The type of the associated heartbeat message.
 /// </typeparam>
 /// <param name="intervalInSeconds">
 /// The regular interval, in seconds, at which the message is published.
 /// </param>
 /// <param name="entityType">
 /// The messaging entity type that is used when publishing the message. The default value is
 /// <see cref="MessagingEntityType.Topic" />.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="intervalInSeconds" /> is less than or equal to zero -or- <paramref name="entityType" /> is equal to
 /// <see cref="MessagingEntityType.Unspecified" />.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// The schedule already contains an item with matching specifications.
 /// </exception>
 public void AddItem <TMessage>(Int32 intervalInSeconds, MessagingEntityType entityType)
     where TMessage : HeartbeatMessage, new() => AddItem(new HeartbeatScheduleItem <TMessage>(intervalInSeconds, entityType));
コード例 #23
0
 public AmqpMessageReceiver(string entityName, MessagingEntityType entityType, ReceiveMode mode, int prefetchCount, ServiceBusConnection serviceBusConnection, ICbsTokenProvider cbsTokenProvider)
     : this(entityName, entityType, mode, prefetchCount, serviceBusConnection, cbsTokenProvider, null)
 {
 }
コード例 #24
0
 /// <summary>
 /// Adds the specified heartbeat schedule item to the schedule.
 /// </summary>
 /// <param name="intervalInSeconds">
 /// The regular interval, in seconds, at which the message is published.
 /// </param>
 /// <param name="entityType">
 /// The messaging entity type that is used when publishing the message. The default value is
 /// <see cref="MessagingEntityType.Topic" />.
 /// </param>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="intervalInSeconds" /> is less than or equal to zero -or- <paramref name="entityType" /> is equal to
 /// <see cref="MessagingEntityType.Unspecified" />.
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// The schedule already contains an item with matching specifications.
 /// </exception>
 public void AddItem(Int32 intervalInSeconds, MessagingEntityType entityType) => AddItem <HeartbeatMessage>(intervalInSeconds, entityType);
コード例 #25
0
 public MessagingEntityDoesNotAlreadyExistException(string path, MessagingEntityType messagingEntityType)
     : base(string.Format("A messaging entity with a path of \"{0}\" of type {1} does not exist and was not configured to be created automatically.", path, messagingEntityType))
 {
     Path = path;
     MessagingEntityType = messagingEntityType;
 }
コード例 #26
0
 /// <summary>
 /// Asynchronously publishes the specified message to a bus.
 /// </summary>
 /// <typeparam name="TMessage">
 /// The type of the message to publish.
 /// </typeparam>
 /// <param name="message">
 /// The message to publish.
 /// </param>
 /// <param name="entityType">
 /// The targeted entity type.
 /// </param>
 /// <param name="controlToken">
 /// A token that ensures thread safety for the operation.
 /// </param>
 /// <returns>
 /// A task representing the asynchronous operation.
 /// </returns>
 protected abstract Task PublishAsync <TMessage>(TMessage message, MessagingEntityType entityType, ConcurrencyControlToken controlToken)
     where TMessage : class, IMessage;
コード例 #27
0
 public MessageTypeMessagingEntityMappingDetails(Type messageType, string path, MessagingEntityType messagingEntityType)
     : this(messageType, path, messagingEntityType, MessagingEntityCreationOptions.None)
 {
 }
コード例 #28
0
 public CreateControlLinkSettings(SbmpMessagingFactory messagingFactory, string entityPath, string entityName, MessagingEntityType entityType, string fromOffset = null) : base(messagingFactory, entityPath, entityName, new Microsoft.ServiceBus.Messaging.Sbmp.LinkInfo()
 {
     LinkId       = messagingFactory.GetNextLinkId(),
     ConnectionId = messagingFactory.ConnectionId,
     LinkType     = LinkType.Control,
     EntityName   = entityName,
     EntityType   = new MessagingEntityType?(entityType),
     FromOffset   = fromOffset
 }, null)
 {
 }
コード例 #29
0
 public MessageTypeMessagingEntityMappingDetails(Type messageType, string path, MessagingEntityType messagingEntityType, MessagingEntityCreationOptions creationOptions)
     : this(messageType, path, messagingEntityType, creationOptions, MessageReceiveMode.ReceiveAndDelete)
 {
 }
コード例 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessageSubscriber{TMessage}" /> class.
 /// </summary>
 /// <param name="mediator">
 /// A processing intermediary that is used to process sub-commands.
 /// </param>
 /// <param name="entityType">
 /// The targeted entity type.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="mediator" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
 /// </exception>
 protected MessageSubscriber(ICommandMediator mediator, MessagingEntityType entityType)
     : base(mediator, MessageHandlerRole.Subscriber, entityType)
 {
     return;
 }
コード例 #31
0
 public SbmpBrowsableMessageSession(string path, string sessionId, MessagingEntityType entityType, SbmpMessagingFactory messagingFactory, Microsoft.ServiceBus.RetryPolicy retryPolicy) : base(ReceiveMode.PeekLock, sessionId, DateTime.MinValue, messagingFactory, retryPolicy)
 {
     this.path       = path;
     this.entityType = entityType;
     this.resetEvent = new AutoResetEvent(true);
 }
コード例 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagePublisher{TMessage}" /> class.
 /// </summary>
 /// <param name="mediator">
 /// A processing intermediary that is used to process sub-commands.
 /// </param>
 /// <param name="client">
 /// A client that facilitates message publishing operations.
 /// </param>
 /// <param name="entityType">
 /// The targeted entity type.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="mediator" /> is <see langword="null" /> -or- <paramref name="client" /> is <see langword="null" />.
 /// </exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="entityType" /> is equal to <see cref="MessagingEntityType.Unspecified" />.
 /// </exception>
 protected MessagePublisher(ICommandMediator mediator, IMessagePublishingClient client, MessagingEntityType entityType)
     : base(mediator, MessageHandlerRole.Publisher, entityType)
 {
     Client = client.RejectIf().IsNull(nameof(client)).TargetArgument;
 }