Example #1
0
        /// <summary>
        /// Creates a RabbitMQ exchange
        /// </summary>
        /// <param name="configuration">Queue configuration</param>
        /// <returns>Informations about the created exchange</returns>
        public static RabbitExchangeInfo CreateExchange(QueueConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            // Exchange name
            var exchangeName = "Queue4GP";
            // Topic type
            var exchangeType = "topic";
            // Connection
            var factory = new ConnectionFactory
            {
                HostName = configuration.Host,
                Port     = configuration.Port,
                UserName = configuration.User,
                Password = configuration.Password
            };
            var connection = factory.CreateConnection();
            // Channel
            var channel = connection.CreateModel();

            channel.ExchangeDeclare(exchange: exchangeName, type: exchangeType, durable: true, autoDelete: false);

            // Returns the result
            return(new RabbitExchangeInfo
            {
                Connection = connection,
                ExchangeName = exchangeName,
                Channel = channel
            });
        }
Example #2
0
 /// <summary>
 /// Creates a new instance of <see cref="QueueSubscriber{TMessage}"/>
 /// </summary>
 /// <param name="configuration">Configurations</param>
 /// <param name="handler">Handler of messages</param>
 public QueueSubscriber(QueueConfiguration configuration, IQueueHandler <TMessage> handler)
 {
     QueueHandler  = handler ?? throw new ArgumentNullException(nameof(handler));
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }
Example #3
0
 /// <summary>
 /// Creates a new instance of <see cref="QueuePublisher{TMessage}"/>
 /// </summary>
 /// <param name="configuration">Configurations to use</param>
 public QueuePublisher(QueueConfiguration configuration)
 {
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
 }