Example #1
0
        public RabbitBus(
            IEasyNetQLogger logger,
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IRpc rpc,
            ISendReceive sendReceive,
            IConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.logger      = logger;
            this.conventions = conventions;
            this.advancedBus = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.rpc                     = rpc;
            this.sendReceive             = sendReceive;
            this.connectionConfiguration = connectionConfiguration;

            advancedBus.Connected    += OnConnected;
            advancedBus.Disconnected += OnDisconnected;
        }
Example #2
0
        public AzureBus(
            IAzureNetQLogger logger,
            IConventions conventions,
            IRpc rpc,
            ISendReceive sendReceive,
            IAzureAdvancedBus advancedBus,
            IConnectionConfiguration connectionConfiguration,
            ISerializer serializer)
        {
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(serializer, "serializer");

            this.logger                  = logger;
            this.conventions             = conventions;
            this.rpc                     = rpc;
            this.sendReceive             = sendReceive;
            this.advancedBus             = advancedBus;
            this.connectionConfiguration = connectionConfiguration;
            this.serializer              = serializer;
            this.exceptionHandler        = new ExceptionHandler(logger);
        }
Example #3
0
        /// <summary>
        /// Send a message directly to a queue
        /// </summary>
        /// <typeparam name="T">The type of message to send</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to send to</param>
        /// <param name="message">The message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        public static Task SendAsync <T>(
            this ISendReceive sendReceive,
            string queue,
            T message,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.SendAsync(queue, message, c => { }, cancellationToken));
        }
Example #4
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The synchronous function that handles the message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Action <T> onMessage,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive(queue, onMessage, c => { }, cancellationToken));
        }
Example #5
0
        /// <summary>
        /// Send a message directly to a queue
        /// </summary>
        /// <typeparam name="T">The type of message to send</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to send to</param>
        /// <param name="message">The message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        public static void Send <T>(
            this ISendReceive sendReceive,
            string queue,
            T message,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            sendReceive.Send(queue, message, c => { }, cancellationToken);
        }
Example #6
0
 public static async Task SendBatchAsync <T>(
     this ISendReceive sendReceive,
     string queue,
     IEnumerable <T> messages,
     CancellationToken cancellationToken = default
     )
 {
     foreach (var message in messages)
     {
         await sendReceive.SendAsync(queue, message, cancellationToken).ConfigureAwait(false);
     }
 }
Example #7
0
 public RabbitBus(
     IConventions conventions,
     IAdvancedBus advancedBus,
     ISendReceive sendReceive,
     IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
     IMessageDeliveryModeStrategy messageDeliveryModeStrategy)
 {
     this.conventions = conventions;
     this.advancedBus = advancedBus;
     this.sendReceive = sendReceive;
     this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
     this.messageDeliveryModeStrategy    = messageDeliveryModeStrategy;
 }
Example #8
0
        /// <summary>
        /// Send a message directly to a queue
        /// </summary>
        /// <typeparam name="T">The type of message to send</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to send to</param>
        /// <param name="message">The message</param>
        /// <param name="configure">
        ///     Fluent configuration e.g. x => x.WithPriority(2)
        /// </param>
        /// <param name="cancellationToken">The cancellation token</param>
        public static void Send <T>(
            this ISendReceive sendReceive,
            string queue,
            T message,
            Action <ISendConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            sendReceive.SendAsync(queue, message, configure, cancellationToken)
            .GetAwaiter()
            .GetResult();
        }
Example #9
0
 public RabbitBus(
     IAdvancedBus advanced,
     IPubSub pubSub,
     IRpc rpc,
     ISendReceive sendReceive,
     IScheduler scheduler,
     IRabbitMQPersistentConnection connection)
 {
     _advanced    = advanced;
     _pubsub      = pubSub;
     _rpc         = rpc;
     _sendreceive = sendReceive;
     _scheduler   = scheduler;
     _connection  = connection;
 }
Example #10
0
        /// <summary>
        /// Send a message directly to a queue
        /// </summary>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to send to</param>
        /// <param name="message">The message</param>
        /// <param name="messageType">The message type</param>
        /// <param name="configure">
        ///     Fluent configuration e.g. x => x.WithPriority(2)
        /// </param>
        /// <param name="cancellationToken">The cancellation token</param>
        public static Task SendAsync(
            this ISendReceive sendReceive,
            string queue,
            object message,
            Type messageType,
            Action <ISendConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            var sendDelegate = SendDelegates.GetOrAdd(messageType, t =>
            {
                var sendMethodInfo = typeof(ISendReceive).GetMethod("SendAsync");
                if (sendMethodInfo == null)
                {
                    throw new MissingMethodException(nameof(ISendReceive), "SendAsync");
                }

                var genericSendMethodInfo           = sendMethodInfo.MakeGenericMethod(t);
                var sendReceiveParameter            = Expression.Parameter(typeof(ISendReceive), "sendReceive");
                var queueParameter                  = Expression.Parameter(typeof(string), "queue");
                var messageParameter                = Expression.Parameter(typeof(object), "message");
                var messageTypeParameter            = Expression.Parameter(typeof(Type), "messageType");
                var configureParameter              = Expression.Parameter(typeof(Action <ISendConfiguration>), "configure");
                var cancellationTokenParameter      = Expression.Parameter(typeof(CancellationToken), "cancellationToken");
                var genericSendMethodCallExpression = Expression.Call(
                    sendReceiveParameter,
                    genericSendMethodInfo,
                    queueParameter,
                    Expression.Convert(messageParameter, t),
                    configureParameter,
                    cancellationTokenParameter
                    );
                var lambda = Expression.Lambda <NonGenericSendDelegate>(
                    genericSendMethodCallExpression,
                    sendReceiveParameter,
                    queueParameter,
                    messageParameter,
                    messageTypeParameter,
                    configureParameter,
                    cancellationTokenParameter
                    );
                return(lambda.Compile());
            });

            return(sendDelegate(sendReceive, queue, message, messageType, configure, cancellationToken));
        }
Example #11
0
        /// <summary>
        /// Receive a message from the specified queue. Dispatch them to the given handlers
        /// </summary>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to take messages from</param>
        /// <param name="addHandlers">A function to add handlers</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive(
            this ISendReceive sendReceive,
            string queue,
            Action <IReceiveRegistration> addHandlers,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive(
                       queue,
                       addHandlers,
                       c => { },
                       cancellationToken
                       ));
        }
Example #12
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The asynchronous function that handles the message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Func <T, Task> onMessage,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive <T>(
                       queue,
                       (m, c) => onMessage(m),
                       c => { },
                       cancellationToken
                       ));
        }
Example #13
0
        /// <summary>
        /// Receive a message from the specified queue. Dispatch them to the given handlers
        /// </summary>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to take messages from</param>
        /// <param name="addHandlers">A function to add handlers</param>
        /// <param name="configure">Action to configure consumer with</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive(
            this ISendReceive sendReceive,
            string queue,
            Action <IReceiveRegistration> addHandlers,
            Action <IConsumerConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.ReceiveAsync(
                       queue,
                       addHandlers,
                       configure,
                       cancellationToken
                       ).GetAwaiter().GetResult());
        }
Example #14
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The asynchronous function that handles the message</param>
        /// <param name="configure">Action to configure consumer with</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Func <T, CancellationToken, Task> onMessage,
            Action <IConsumerConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.ReceiveAsync(
                       queue,
                       onMessage,
                       configure,
                       cancellationToken
                       ).GetAwaiter().GetResult());
        }
Example #15
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The synchronous function that handles the message</param>
        /// <param name="configure">Action to configure consumer with</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Action <T> onMessage,
            Action <IConsumerConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            var onMessageAsync = TaskHelpers.FromAction <T>((m, c) => onMessage(m));

            return(sendReceive.Receive(
                       queue,
                       onMessageAsync,
                       configure,
                       cancellationToken
                       ));
        }
Example #16
0
        /// <summary>
        ///     Creates RabbitBus
        /// </summary>
        /// <param name="advanced">The advanced bus</param>
        /// <param name="pubSub">The pub-sub</param>
        /// <param name="rpc">The rpc</param>
        /// <param name="sendReceive">The send-receive</param>
        /// <param name="scheduler">The scheduler</param>
        public RabbitBus(
            IAdvancedBus advanced,
            IPubSub pubSub,
            IRpc rpc,
            ISendReceive sendReceive,
            IScheduler scheduler
            )
        {
            Preconditions.CheckNotNull(advanced, "advanced");
            Preconditions.CheckNotNull(pubSub, "pubSub");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(scheduler, "scheduler");

            Advanced    = advanced;
            PubSub      = pubSub;
            Rpc         = rpc;
            SendReceive = sendReceive;
            Scheduler   = scheduler;
        }
Example #17
0
        public RabbitBus(
            IConventions conventions,
            IAdvancedBus advancedBus,
            IExchangeDeclareStrategy exchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IRpc rpc,
            ISendReceive sendReceive,
            ConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(conventions, nameof(conventions));
            Preconditions.CheckNotNull(advancedBus, nameof(advancedBus));
            Preconditions.CheckNotNull(exchangeDeclareStrategy, nameof(exchangeDeclareStrategy));
            Preconditions.CheckNotNull(rpc, nameof(rpc));
            Preconditions.CheckNotNull(sendReceive, nameof(sendReceive));
            Preconditions.CheckNotNull(connectionConfiguration, nameof(connectionConfiguration));

            this.conventions                 = conventions;
            this.advancedBus                 = advancedBus;
            this.exchangeDeclareStrategy     = exchangeDeclareStrategy;
            this.messageDeliveryModeStrategy = messageDeliveryModeStrategy;
            this.rpc                     = rpc;
            this.sendReceive             = sendReceive;
            this.connectionConfiguration = connectionConfiguration;
        }
Example #18
0
        public RabbitBus(
            IConventions conventions,
            IAdvancedBus advancedBus,
            IPublishExchangeDeclareStrategy publishExchangeDeclareStrategy,
            IMessageDeliveryModeStrategy messageDeliveryModeStrategy,
            IRpc rpc,
            ISendReceive sendReceive,
            ConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(advancedBus, "advancedBus");
            Preconditions.CheckNotNull(publishExchangeDeclareStrategy, "publishExchangeDeclareStrategy");
            Preconditions.CheckNotNull(rpc, "rpc");
            Preconditions.CheckNotNull(sendReceive, "sendReceive");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.conventions = conventions;
            this.advancedBus = advancedBus;
            this.publishExchangeDeclareStrategy = publishExchangeDeclareStrategy;
            this.messageDeliveryModeStrategy    = messageDeliveryModeStrategy;
            this.rpc                     = rpc;
            this.sendReceive             = sendReceive;
            this.connectionConfiguration = connectionConfiguration;
        }
Example #19
0
 public NonGenericSendReceiveExtensionsTests()
 {
     sendReceive = Substitute.For <ISendReceive>();
 }