Пример #1
0
        public async Task FuturePublishAsync <T>(DateTime futurePublishDate, T message, string cancellationKey = null) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            var scheduleMeType     = typeof(ScheduleMe);
            var scheduleMeExchange = await publishExchangeDeclareStrategy.DeclareExchangeAsync(advancedBus, scheduleMeType, ExchangeType.Topic).ConfigureAwait(false);

            var baseMessageType     = typeof(T);
            var concreteMessageType = message.GetType();
            var serializedMessage   = messageSerializationStrategy.SerializeMessage(new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(concreteMessageType)
                }
            });
            var scheduleMe = new ScheduleMe
            {
                WakeTime          = futurePublishDate,
                CancellationKey   = cancellationKey,
                InnerMessage      = serializedMessage.Body,
                MessageProperties = serializedMessage.Properties,
                BindingKey        = typeNameSerializer.Serialize(typeof(T)),
                ExchangeType      = ExchangeType.Topic,
                Exchange          = conventions.ExchangeNamingConvention(baseMessageType),
                RoutingKey        = "#"
            };
            var easyNetQMessage = new Message <ScheduleMe>(scheduleMe)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(scheduleMeType)
                }
            };
            await advancedBus.PublishAsync(scheduleMeExchange, conventions.TopicNamingConvention(scheduleMeType), false, easyNetQMessage).ConfigureAwait(false);
        }
Пример #2
0
        public Task FuturePublishAsync <T>(DateTime futurePublishDate, string cancellationKey, T message) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            var messageType = typeof(ScheduleMe);

            return(publishExchangeDeclareStrategy.DeclareExchangeAsync(advancedBus, messageType, ExchangeType.Topic).Then(exchange =>
            {
                var typeName = typeNameSerializer.Serialize(typeof(T));
                var messageBody = serializer.MessageToBytes(message);
                var scheduleMe = new ScheduleMe
                {
                    WakeTime = futurePublishDate,
                    BindingKey = typeName,
                    CancellationKey = cancellationKey,
                    InnerMessage = messageBody
                };
                var easyNetQMessage = new Message <ScheduleMe>(scheduleMe)
                {
                    Properties =
                    {
                        DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(messageType)
                    }
                };
                return advancedBus.PublishAsync(exchange, conventions.TopicNamingConvention(messageType), false, false, easyNetQMessage);
            }));
        }
Пример #3
0
        public virtual async Task PublishAsync <T>(T message, Action <IPublishConfiguration> configure) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(configure, "configure");

            var configuration = new PublishConfiguration(conventions.TopicNamingConvention(typeof(T)));

            configure(configuration);

            var messageType     = typeof(T);
            var easyNetQMessage = new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(messageType)
                }
            };

            if (configuration.Priority != null)
            {
                easyNetQMessage.Properties.Priority = configuration.Priority.Value;
            }
            if (configuration.Expires != null)
            {
                easyNetQMessage.Properties.Expiration = configuration.Expires.ToString();
            }

            var exchange = await publishExchangeDeclareStrategy.DeclareExchangeAsync(advancedBus, messageType, ExchangeType.Topic).ConfigureAwait(false);

            await advancedBus.PublishAsync(exchange, configuration.Topic, false, easyNetQMessage).ConfigureAwait(false);
        }
Пример #4
0
        public async Task PublishAsync <T>(T message, string topic) where T : class
        {
            GuardHelper.ArgumentNotNull(() => message);
            GuardHelper.ArgumentNotEmpty(() => topic);
            var messageType   = typeof(T);
            var rabbitMessage = GetRabbitMessage(message, messageType);
            var exchange      = await publishExchangeDeclareStrategy.DeclareExchangeAsync(
                advancedBus, messageType, ExchangeType.Topic).ConfigureAwait(false);

            await advancedBus.PublishAsync(exchange, topic, rabbitMessage).ConfigureAwait(false);
        }
Пример #5
0
        public virtual Task PublishAsync <T>(T message, string topic) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(topic, "topic");
            var messageType = typeof(T);

            return(publishExchangeDeclareStrategy.DeclareExchangeAsync(advancedBus, messageType, ExchangeType.Topic).Then(exchange =>
            {
                var easyNetQMessage = new Message <T>(message)
                {
                    Properties = { DeliveryMode = (byte)(messageDeliveryModeStrategy.IsPersistent(messageType) ? 2 : 1) }
                };
                return advancedBus.PublishAsync(exchange, topic, false, false, easyNetQMessage);
            }));
        }
Пример #6
0
        public virtual async Task PublishAsync <T>(T message, string topic) where T : class
        {
            Preconditions.CheckNotNull(message, "message");
            Preconditions.CheckNotNull(topic, "topic");
            var messageType     = typeof(T);
            var easyNetQMessage = new Message <T>(message)
            {
                Properties =
                {
                    DeliveryMode = messageDeliveryModeStrategy.GetDeliveryMode(messageType)
                }
            };
            var exchange = await publishExchangeDeclareStrategy.DeclareExchangeAsync(advancedBus, messageType, ExchangeType.Topic).ConfigureAwait(false);

            await advancedBus.PublishAsync(exchange, topic, false, easyNetQMessage).ConfigureAwait(false);
        }