Inheritance: PublisherConfigurator, IRpcPublisherConfigurator
Esempio n. 1
0
        public IRpcAsyncPublisher CreateAsyncRpcPublisher(Action <IRpcPublisherConfigurator> configure = null)
        {
            RpcPublisherConfigurator configuration = _createRpcPublisherConfigurator(configure);

            IModel model = _connection.CreateModel();

            IRpcConsumer consumer = new RpcConsumer(BusId, model, _messageHelper, new Dictionary <string, ISerializer>
            {
                { configuration.Serializer.ContentType, configuration.Serializer }
            }, configuration.Trace);

            return(new RpcAsyncPublisher(model, BusId, configuration, _messageHelper, _sendHelper, consumer));
        }
Esempio n. 2
0
        protected RpcPublisherBase(IModel model, string busId, RpcPublisherConfigurator configuration, IMessageHelper messageHelper, ISendHelper sendHelper, IRpcConsumer consumer)
            : base(model, busId, configuration, messageHelper, sendHelper)
        {
            _consumer = consumer;

            const string fastReplyQueue = "amq.rabbitmq.reply-to";

            if (configuration.UseFastReply)
            {
                _consumerTag = model.BasicConsume(fastReplyQueue, true, configuration.ConsumerTag, consumer);

                _replyTo = fastReplyQueue;
            }
            else
            {
                QueueDeclareOk queueDeclare = model.QueueDeclare("", false, true, true, new Dictionary <string, object>());

                if (string.IsNullOrEmpty(configuration.ReplyExchange))
                {
                    // Use default exchange, no need to bind queue

                    _replyTo = queueDeclare.QueueName;
                }
                else
                {
                    // Bind queue to specified exchange by replyTo or generate unique routing key
                    string routingKey = configuration.ReplyTo ?? NewMiniGuid();

                    model.QueueBind(queueDeclare.QueueName, configuration.ReplyExchange, routingKey);

                    _replyTo = routingKey;
                }

                _consumerTag = model.BasicConsume(queueDeclare.QueueName, true, configuration.ConsumerTag, consumer);
            }
        }
Esempio n. 3
0
 public RpcSyncPublisher(IModel model, string busId, RpcPublisherConfigurator configuration, IMessageHelper messageHelper, ISendHelper sendHelper, IRpcConsumer consumer)
     : base(model, busId, configuration, messageHelper, sendHelper, consumer)
 {
 }
Esempio n. 4
0
        public RabbitMQBus(Action <IBusConfigurator> busConfigurator = null)
        {
            BusConfigurator busConfiguration = new BusConfigurator();

            if (busConfigurator != null)
            {
                busConfigurator(busConfiguration);
            }

            BusId             = busConfiguration.BusId;
            BusConnectionName = busConfiguration.ConnectionProvidedName;

            _exchange = "amq.headers";

            string username = "******";
            string password = "******";

            if (!string.IsNullOrEmpty(busConfiguration.ConnectionString.Endpoint))
            {
                _exchange = busConfiguration.ConnectionString.Endpoint;
            }

            if (!string.IsNullOrEmpty(busConfiguration.ConnectionString.Username))
            {
                username = busConfiguration.ConnectionString.Username;
            }

            if (!string.IsNullOrEmpty(busConfiguration.ConnectionString.Password))
            {
                password = busConfiguration.ConnectionString.Password;
            }

            ConnectionFactory factory = new ConnectionFactory
            {
                HostName = busConfiguration.ConnectionString.Host,
                Port     = busConfiguration.ConnectionString.Port,
                AutomaticRecoveryEnabled = true,
                TopologyRecoveryEnabled  = true,
                UserName    = username,
                Password    = password,
                VirtualHost = busConfiguration.ConnectionString.VirtualHost
            };

            _connection = factory.CreateConnection(busConfiguration.ConnectionProvidedName);

            _connection.ConnectionBlocked += (sender, args) =>
            {
                busConfiguration.ConnectionBlocked(args.Reason);
            };

            _connection.ConnectionUnblocked += (sender, args) =>
            {
                busConfiguration.ConnectionUnblocked();
            };

            _createSubscriberConfigurator = configure =>
            {
                SubscriberConfigurator configurator = new SubscriberConfigurator(_exchange, busConfiguration.ReplyExchange, busConfiguration.ErrorSubscriber, busConfiguration.ReceiveSelfPublish, busConfiguration.Trace, () => busConfiguration.Blocked);

                if (configure != null)
                {
                    configure(configurator);
                }

                return(configurator);
            };

            _createPublisherConfigurator = configure =>
            {
                PublisherConfigurator configurator = new PublisherConfigurator(_exchange, busConfiguration.ErrorHandler, busConfiguration.Trace, () => busConfiguration.Blocked);

                if (configure != null)
                {
                    configure(configurator);
                }

                return(configurator);
            };

            _createRpcPublisherConfigurator = configure =>
            {
                RpcPublisherConfigurator configurator = new RpcPublisherConfigurator(_exchange, busConfiguration.UseFastReply, busConfiguration.ReplyExchange, busConfiguration.ErrorHandler, busConfiguration.Trace, () => busConfiguration.Blocked);

                if (configure != null)
                {
                    configure(configurator);
                }

                return(configurator);
            };
        }