Last active
July 12, 2016 13:13
-
-
Save mahesh-singh/a3ae08591dfec60212044f447a9fff59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amqp://<User Name>:<Password>@<Host>:<Port>/<vhost> | |
amqp://mahesh:123456@NDI-LAP-337:5672/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConnectionFactory _ConnectionFactory = new ConnectionFactory | |
{ | |
Uri = ConnectionInstanceManager.InitializeRabbitMqConnectionUri(connectionStringName, true) | |
}; | |
using (IModel consumerChannel = Connection.CreateModel()) | |
{ | |
//Declare topic exchange which is durable | |
Channel.ExchangeDeclare("Super-Exchange", ExchangeType.Topic, true); | |
consumerChannel.QueueDeclare("super-report-processer-queue", _queueProperties.Durable, _queueProperties.Exclusive, | |
_queueProperties.AutoDelete, _queueProperties.Arguments); | |
//Route key binding with queue | |
consumerChannel.QueueBind(queueName, _exchangeProperties.Name, routeKey); | |
var consumer = new QueueingBasicConsumer(consumerChannel); | |
//Consume the message (queue name, noAck, consumer) | |
consumerChannel.BasicConsume("super-report-processer-queue", false, consumer); | |
while (true) | |
{ | |
BasicDeliverEventArgs eventArgs; | |
if (consumer.Queue.Dequeue(5000, out eventArgs)) | |
{ | |
MessageInfo messageItem = _messageSerializer.ByteArrayToMessageInfo<MessageInfo>(eventArgs.Body); | |
//process your message | |
consumerChannel.BasicAck(eventArgs.DeliveryTag, false); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ConnectionFactory _ConnectionFactory = new ConnectionFactory | |
{ | |
Uri = ConnectionInstanceManager.InitializeRabbitMqConnectionUri(connectionStringName, true) | |
}; | |
using (Channel = _ConnectionFactory.CreateModel()) | |
{ | |
byte[] message = this._MessageSerializer.MessageToByteArray(MessageItem, IgnorableSerializerContractResolver); | |
//Declare topic exchange which is durable | |
Channel.ExchangeDeclare("Super-Exchange", ExchangeType.Topic, true); | |
//Message property | |
IBasicProperties _BasicProperties = new BasicProperties | |
{ | |
ContentEncoding = "utf8", | |
ContentType = "application/json", | |
Timestamp = new AmqpTimestamp(GetEpochTimeStamp()), | |
}; | |
_BasicProperties.SetPersistent(true); | |
//Publisher confirm | |
Channel.ConfirmSelect(); | |
Channel.BasicPublish(_MessageExchangeProperties.Name, MessageItem.RouteKey, basicProperties, message); | |
//Wait for confirmation from RabbitMQ | |
Channel.WaitForConfirmsOrDie(TimeSpan.FromMilliseconds(_MessageExchangeProperties.WaitForConfirmsTimeOut)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rabbitmq-service.bat start | |
rabbitmqctl stop | |
rabbitmqctl stop_app | |
rabbitmqctl start_app | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment