public static void Send(RMQMessage rmqMsg)
        {
            var factory = new ConnectionFactory()
            {
                HostName    = rmqMsg.HostName,
                VirtualHost = rmqMsg.VirtualHost,
                UserName    = rmqMsg.UserName,
                Password    = rmqMsg.Password
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: rmqMsg.QueueName,
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    var body = Encoding.UTF8.GetBytes(rmqMsg.Message);

                    channel.BasicPublish(exchange: rmqMsg.Exchange,
                                         routingKey: rmqMsg.RoutingKeyName,
                                         basicProperties: null,
                                         body: body);

                    // Console.WriteLine(" [x] Sent {0}", rmqMsg.Message);
                }
        }
        public void Receive(RMQMessage rmqMsg)
        {
            WriteLine("started receiver");

            var factory = new ConnectionFactory()
            {
                HostName    = rmqMsg.HostName,
                VirtualHost = rmqMsg.VirtualHost,
                UserName    = rmqMsg.UserName,
                Password    = rmqMsg.Password
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: rmqMsg.QueueName,
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var body    = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        // WriteLine(" [x] Received {0}", message);
                    };
                    channel.BasicConsume(queue: rmqMsg.QueueName, autoAck: true, consumer: consumer);

                    Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
        }
 public NewScrapeFileListener(RMQMessage options,
                              ImportScrapeData importData,
                              cvConfig cvConfiguration,
                              IConfiguration cfg) : base(options)
 {
     this.cfg             = cfg;
     this.cvConfiguration = cvConfiguration;
     this.importData      = importData;
 }
示例#4
0
        public TwiMLResult ReceiveSms(SmsRequest incomingMessage)
        {
            RMQMessage message = new RMQMessage();

            message.Message        = incomingMessage.Body;
            message.isSendToExpert = !incomingMessage.From.Equals(WhatsAppConstants.WHATSAPPPREFIX + "919561172408");
            _sender.sendSms(_configurationRMQ.Value, message);

            /*
             * messagingResponse.Message("Response: Hi how may I help you? : " + incomingMessage.Body);*/

            //return TwiML(messagingResponse);
            return(null);
        }
        public RabbitListener(RMQMessage options)
        {
            try
            {
                var factory = new ConnectionFactory()
                {
                    VirtualHost = options.VirtualHost,
                    HostName    = options.HostName,
                    UserName    = options.UserName,
                    Password    = options.Password
                };

                this.connection = factory.CreateConnection();
                this.channel    = connection.CreateModel();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"RabbitListener init error,ex:{ex.Message}");
            }
            this._options = options;
        }
示例#6
0
        public bool PublishMessage(System.Collections.Generic.List <System.Collections.Generic.KeyValuePair <string, string> > imageDetailsForPikleGeneration)
        {
            try
            {
                var rmqMessage = new RMQMessage
                {
                    ImageDetailsForPikleGeneration = imageDetailsForPikleGeneration
                };

                //var exchange = _RMQBus.ExchangeDeclare(appSettings.RMQPublisherTopic, ExchangeType.Topic);
                //var rmqPayload = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(rmqMessage));
                //_RMQBus.Publish(exchange, appSettings.RMQPublisherTopic, true, new MessageProperties(), rmqPayload);
            }
            catch (Exception exception)
            {
                return(false);
            }



            return(true);
        }
        public ActionResult SendMessageToRabbitQueue(RMQMessage messageBody)
        {
            var response = _sender.sendSms(_configuration.Value, messageBody);

            return(Content(response));
        }
 public static void Send(RMQMessage rmqMsg, string message)
 {
     rmqMsg.Message = message;
     Send(rmqMsg);
 }