35. var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish("", "hello", null, body);
Console.WriteLine(" [x] Sent {0}", message);
}
}
Queue Declare
36. var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("hello", true, consumer);
Console.WriteLine(" [*] Waiting for messages." +
"To exit press CTRL+C");
while (true)
{
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0}", message);
}
}
}
51. Easynetq save your time
//many simplification
var bus = RabbitHutch.CreateBus("host=ubuntu:5672,ubuntu:5673");
//also give freedom
var advancedBus = RabbitHutch.CreateBus("host=localhost").Advanced
54. Large Message
Messaging in general should be small
AMPQ support very large messages
RabbitMQ you can use large messages but you need to be careful
MSMQ-Message Queuing is limited
in the size of documents that can
be processed. The maximum size
document that Message Queuing
supports is 4 MB if the document
is in ASCII. The message queue
can handle a maximum of 2 MB if
the document is in Unicode.
58. //no retry
var ea = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
channel.BasicReject(ea.DeliveryTag,false);
//retry
var ea = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
channel.BasicReject(ea.DeliveryTag,true);
80. RabbitMQ Federation
•Supports replication across different administrative
domains
•Supports mix of Erlang and RabbitMQ versions
•Supports Network Partitions
•Specificity - not everything has to be federated
99. RabbitMQ is extremely efficient,
widely deployed & tested
message broker but can hit
performance, if tuned for more
durability and reliability. It’s
more targeted towards serving
enterprise messaging with
advanced routing requirements.
Redis is quick to start,
lightweight & fast broker but
does Not support reliable
delivery Hence can be chosen
for applications where in case
system terminates, losing the
information about tasks for a
few minutes is Not critical.
http://goo.gl/J5ak0j
Advanced Message Queuing Protocol
Message Queue Telemetry Transport—IBM-- binary packet payload--low bandwidth, high latency networks such as dial up lines and satellite links
Simple/Streaming Text Oriented Messaging Protocol--browser, mobile app, or machine in real-time
Publish from a protocol consume from another protocol
Single point of failure
Do not start showing other pattern
sysv-rc-conf
nano /etc/apt/sources.list
deb http://www.rabbitmq.com/debian/ testing main
wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
apt-get update
sudo apt-get install rabbitmq-server
Message Queuing is limited in the size of documents that can be processed. The maximum size document that Message Queuing supports is 4 MB if the document is in ASCII. The message queue can handle a maximum of 2 MB if the document is in Unicode.
/debug
/production
demo
C:\Program Files (x86)\RabbitMQ Server\rabbitmq_server-3.4.3\sbin>rabbitmqctl jo
in_cluster --ram rabbit@exdev
Clustering node rabbit@JINOM with rabbit@exdev ...
Error: {inconsistent_cluster,"OTP version mismatch: local node is 17.4, remote n
ode R15B01"}
Check erlang verssion
erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' –noshell
in_cluster --ram rabbit@exdev
Clustering node rabbit@JINOM with rabbit@exdev ...
On Unix systems, the cookie will be typically located in /var/lib/rabbitmq/.erlang.cookie or$HOME/.erlang.cookie.
On Windows, the locations are C:\Users\Current User\.erlang.cookie(%HOMEDRIVE% + %HOMEPATH%\.erlang.cookie) orC:\Documents and Settings\Current User\.erlang.cookie, and C:\Windows\.erlang.cookie for RabbitMQ Windows service. If Windows service is used, the cookie should be placed in both places.
As an alternative, you can insert the option "-setcookie cookie" in the erl call in the rabbitmq-serverand rabbitmqctl scripts.
https://www.youtube.com/watch?v=CAak2ayFcV0
https://github.com/zenoss/ZenPacks.zenoss.RabbitMQ
http://looselycoupledlabs.com/2014/08/monitoring-rabbitmq/
http://www.rabbitmq.com/how.html have a section