Haukcode.AmqpJsonAppender.AmqpTransport.Send C# (CSharp) Method

Send() public method

public Send ( string message ) : void
message string
return void
        public void Send(string message)
        {
            try
            {
                var model = Model;
                var props = model.CreateBasicProperties();
                props.DeliveryMode = 1;

                if (!stopped)
                    model.BasicPublish(Queue, "elasticsearch", props, Encoding.UTF8.GetBytes(message));
            }
            catch(RabbitMQ.Client.Exceptions.BrokerUnreachableException)
            {
                Reset();
                // Back off
                System.Threading.Thread.Sleep(5000);
            }
            catch
            {
                Reset();
            }
        }

Usage Example

Example #1
0
        /// <summary>
        /// Sending the message via AMQP
        /// </summary>
        /// <param name="message">Message to be sent</param>
        private void SendAmqpMessage(string message)
        {
            if (amqpTransport == null)
            {
                amqpTransport = new AmqpTransport()
                {
                    IpAddress   = GetIpAddressFromHostName(),
                    Port        = AmqpServerPort,
                    VirtualHost = AmqpVirtualHost,
                    User        = AmqpUser,
                    Password    = AmqpPassword,
                    Queue       = AmqpQueue
                };
            }

            amqpTransport.Send(message);
        }