RabbitMQ With C# - Code-Adda - Cara Instalasi
RabbitMQ With C# - Code-Adda - Cara Instalasi
com/2019/01/rabbitmq-with-c/
CODE-ADDA
LIFE BETWEEN CODE AND COFFEE
INTERVIEW QUESTIONS
SEARCH …
TOP POSTS
1 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
It is quite popular, free and open Source message broker that How To Enable SSL or
implements AMQP(Advanced Message Queuing Protocol). HTTPS In Apache
It is written in Erlang programming language. You don’t need Tomcat 8
to learn Erlang to go through with RabbitMQ. Erlang is just a
Validating UIDAI
prerequisite because it is written in Erlang and it needs that
Aadhaar number using
to run in your system.
Verhoe� Algorithm
Provides client library in di�erent programming languages
(Java, C#, Python, Javascript, etc) for Interactions with Creating your �rst WEB
RabbitMQ server. API Project
ASP.NET
Awards
AWS
C#
Dot Net
General
INTERVIEW QUESTIONS
Producer: Producer is a component that sends or can say
Java
push data to message broker in Queue.
Java 8
Exchange: Exchange is a component which comes in action
when a producer creates a message that will not directly be Learning
sent to a queue, instead �rst the message will be sent to
Maven
exchanges, then after that a routing agent reads and sends it
to the appropriate queue with help of header attributes, PYTHON
bindings, and routing keys.
Spring Boot
Queue: Queue is a component which acts like message
bu�er which can hold a large amount of data. It works on the SQL SERVER
basis of FIFO (First in First Out
TIPS/TRICKS
Consumer: Consumer is a component which basically
2 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
Note :
SUBSCRIBE TO BLOG VIA
Many producers can send messages that go to one EMAIL
queue, and many consumers can try to receive data
from one queue Enter your email address to
subscribe to this blog and
receive noti�cations of new
For more Information, I suggest you read their o�cial
posts by email.
documentation at https://www.rabbitmq.com/getstarted.html
E mail A ddress
3 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
4 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
RabbitMQ Management UI
5 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
1 using RabbitMQ.Client;
2 using System;
3 using System.Text;
4
5 namespace HelloWorld_RabbitMQ
6 {
7 class Producer
8 {
9 private const string exchangeName = "HelloWorld_RabbitMQ
10 private const string queueName = "HelloQueue";
11 public static void Main(string[] args)
12 {
13 ConnectionFactory factory = new ConnectionFactory
14
15 using (IConnection connection = factory.CreateConnection
16 {
17 using (IModel channel = connection.CreateModel
18 {
19 channel.ExchangeDeclare(exchangeName, ExchangeType
20 channel.QueueDeclare(queue: queueName,
6 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
21 durable: false,
22 exclusive: false,
23 autoDelete: false,
24 arguments: null);
25
26 string message = "Hello World. This is my first RabbitMQ M
27 var body = Encoding.UTF8.GetBytes(message
28 channel.QueueBind(queueName, exchangeName
29
30 channel.BasicPublish(exchange:exchangeName
31 routingKey: string.
32 basicProperties: null
33 body: body);
34 Console.WriteLine("Message Sent Successfully - {0}
35
36 }
37 }
38 Console.ReadLine();
39 }
40 }
41 }
42
You can also see a new entry of Queue named “HelloQueue” having
one message to read.
7 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
As you can see, we are going to write the same code as we have
written in the Producer class in order to create a connection,
declare exchange and queue.
Note:
At last, we are going to tell the server to deliver the messages from
8 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
1 using System;
2 using System.Text;
3 using RabbitMQ.Client;
4 using RabbitMQ.Client.Events;
5
6 namespace HelloWorld_RabbitMQ
7 {
8 class Consumer
9 {
10 private const string exchangeName = "HelloWorld_RabbitMQ
11 private const string queueName = "HelloQueue";
12
13 private static void Main(string[] args)
14 {
15 ConnectionFactory factory = new ConnectionFactory
16
17 using (IConnection connection = factory.CreateConnection
18 {
19 using (IModel channel = connection.CreateModel
20 {
21 channel.ExchangeDeclare(exchangeName, ExchangeType
22
23 channel.QueueDeclare(queue: queueName,
24 durable
25 exclusive
26 autoDelete
27 arguments
28
9 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
29 channel.QueueBind(queueName, exchangeName
30
31 Console.WriteLine("Waiting for messages"
32
33 var consumer = new EventingBasicConsumer
34 consumer.Received += (model, ea) =>
35 {
36 var body = ea.Body;
37 var message = Encoding.UTF8.GetString
38 Console.WriteLine("Received - {0}",
39 };
40 channel.BasicConsume(queue: queueName,
41 autoAck: true,
42 consumer: consumer);
43
44 Console.ReadLine();
45
46 }
47 }
48 }
49 }
50 }
Once you run the program you can see the message you have
published in the Queue is being displayed on your screen.
Note:
10 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
Share Knowledge :
Related
PREVIOUS NEXT
Custom Banners In Insert File Into
Spring Boot MySQL Database In
Java
Leave a Reply
11 of 12 6/28/2019, 9:17 AM
RabbitMQ with C# - Code-Adda https://code-adda.com/2019/01/rabbitmq-with-c/
Contact
AWARDS AWS C#
Privacy Policy
DOT NET GENERAL
Sitemap
INTERVIEW QUESTIONS
12 of 12 6/28/2019, 9:17 AM