コード例 #1
0
        /// <summary>
        /// Convert HostOption & ExchangeOption & QueueOption to MessageQueueOption
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        protected (HostOption, ExchangeOption, QueueOption) ConvertOption(MessageQueueOption option)
        {
            var hostOption = new HostOption
            {
                ClientName  = option.ClientName,
                Host        = option.Host,
                Port        = option.Port,
                VirtualHost = option.VirtualHost,
                UserName    = option.UserName,
                Password    = option.Password
            };

            var exchangeOption = new ExchangeOption
            {
                ExchangeName  = option.ExchangeName,
                ExchangeType  = option.ExchangeType,
                IsAutoDeleted = option.ExchangeAutoDelete,
                IsDurable     = option.ExchangeDurable,
                RoutingKey    = option.RoutingKey
            };

            var queueOption = new QueueOption
            {
                ConsumerTag   = option.CustomerTag,
                IsAutoDeleted = option.QueueAutoDelete,
                IsDurable     = option.QueueDurable,
                IsExclusive   = option.QueueExclusive,
                QueueName     = option.QueueName,
                AutoAck       = option.QueueAutoAck
            };

            return(hostOption, exchangeOption, queueOption);
        }
コード例 #2
0
        public void Start(MessageQueueOption option)
        {
            var hostOption = new HostOption
            {
                ClientName  = option.ClientName,
                Host        = option.Host,
                Port        = option.Port,
                VirtualHost = option.VirtualHost,
                UserName    = option.UserName,
                Password    = option.Password
            };

            var exchangeOption = new ExchangeOption
            {
                ExchangeName  = option.ExchangeName,
                ExchangeType  = option.ExchangeType,
                IsAutoDeleted = option.ExchangeAutoDelete,
                IsDurable     = option.ExchangeDurable,
                RoutingKey    = option.RoutingKey
            };

            var queueOption = new QueueOption
            {
                QueueName     = option.QueueName,
                IsDurable     = option.QueueDurable,
                IsAutoDeleted = option.QueueAutoDelete,
                IsExclusive   = option.QueueExclusive,
            };

            Start(hostOption, exchangeOption);
        }
コード例 #3
0
        public void Start(MessageQueueOption option)
        {
            var convertOption = ConvertOption(option);

            Start(convertOption.Item1, convertOption.Item2, convertOption.Item3);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            IConsumer consumer = new Consumer(new SimpleJsonMessageDecoder());

            IConsumer <TestModel> consumerT = new Consumer <TestModel>(new SimpleJsonMessageDecoder());


            HostOption hostOption = new HostOption
            {
                ClientName  = "TestCreamCustardBun",
                Host        = "192.168.1.10",
                Port        = 5672,
                VirtualHost = "/dev",
                UserName    = "******",
                Password    = "******",
            };

            ExchangeOption exchangeOption = new ExchangeOption
            {
                ExchangeName  = "temp.exchange",
                ExchangeType  = "direct",
                IsDurable     = false,
                IsAutoDeleted = false,
                RoutingKey    = "temp.routingkey",
            };

            QueueOption queueOption = new QueueOption
            {
                IsDurable     = false,
                IsAutoDeleted = false,
                IsExclusive   = false,
                QueueName     = "temp.queue",
                ConsumerTag   = "",
            };

            MessageQueueOption option = new MessageQueueOption
            {
                ClientName         = "TestCreamCustardBun",
                Host               = "192.168.1.10",
                Port               = 5672,
                VirtualHost        = "/dev",
                UserName           = "******",
                Password           = "******",
                ExchangeName       = "temp.exchange",
                ExchangeType       = "direct",
                ExchangeDurable    = false,
                ExchangeAutoDelete = false,
                RoutingKey         = "temp.routingkey",
                QueueDurable       = false,
                QueueAutoDelete    = false,
                QueueExclusive     = false,
                QueueName          = "temp.queue",
                CustomerTag        = "",
                QueueAutoAck       = true
            };

            consumerT.MessageArrived += Consumer_MessageArrivedT;
            consumerT.Start(option);


            consumer.MessageArrived += Consumer_MessageArrived;
            consumer.Start(option);

            Console.ReadLine();
        }