Examples and materials for RabbitMQ in Depth out in MEAP.
This repository is automatically downloaded and syncronized with the Vagrant file available in the root of the repository.
Copyright 2013 Manning Publications
Examples and materials for RabbitMQ in Depth
License: Other
Examples and materials for RabbitMQ in Depth out in MEAP.
This repository is automatically downloaded and syncronized with the Vagrant file available in the root of the repository.
Copyright 2013 Manning Publications
Looks like the newline characters weren't inputted properly in the 5.2.2 Multi-Ack Consumer Python script.
OBS: when i run this code in shell python instead run the file with python file.py, the code works normally.
The video show the print for all loop in range, but only one or two messages is sent: https://vimeo.com/412936004
Terminal examples:
☁ python3 publisher.py
Loop N: 0
... code omitted for brevity
Loop N: 9
==== publisher.py file!
☁ python3 publisher.py
Loop N: 0
... code omitted for brevity
Loop N: 9
==== publisher.py file!
/\ i run this file 10 times.
And i get this messages:
☁ python3 consumer.py
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 2 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 2 <<')
Message: bytearray(b'Message Number >> 3 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 2 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 0 <<')
Message: bytearray(b'Message Number >> 1 <<')
Message: bytearray(b'Message Number >> 2 <<')
Message: bytearray(b'Message Number >> 3 <<')
Message: bytearray(b'Message Number >> 4 <<')
Source code without comments:
publisher.py:
import rabbitpy
url = 'amqp://guest:guest@localhost:5672/%2F'
connection = rabbitpy.Connection(url)
channel = connection.channel()
exchange = rabbitpy.Exchange(channel, 'chapter2-example')
exchange.declare()
queue = rabbitpy.Queue(channel, 'example')
queue.declare()
queue.bind(exchange, 'example-routing-key')
for message_number in range(0, 10):
message = rabbitpy.Message(channel,
'Message Number >> %i <<' % message_number,
{'content_type': 'text/plain'},
opinionated=True)
message.publish(exchange, 'example-routing-key')
print(f"Loop N: {message_number}")
print("==== publisher.py file!")
consumer.py:
import rabbitpy
url = 'amqp://guest:guest@localhost:5672/%2F'
connection = rabbitpy.Connection(url)
channel = connection.channel()
queue = rabbitpy.Queue(channel, 'example')
while len(queue) > 0:
message = queue.get()
print(f"Message: {message.body}")
message.ack()
print("==== consumer.py file!")
Trying to bring the secondary node up, per instructions, running 'vagrant up secondary' command, getting the following error:
==> secondary: Running provisioner: shell...
secondary: Running: inline script
secondary: Stopping node rabbit@secondary ...
secondary: Error: unable to connect to node rabbit@secondary: nodedown
secondary:
secondary: DIAGNOSTICS
secondary: ===========
secondary:
secondary: attempted to contact: [rabbit@secondary]
secondary:
secondary: rabbit@secondary:
secondary: * connected to epmd (port 4369) on secondary
secondary: * epmd reports node 'rabbit' running on port 25672
secondary: * TCP connection succeeded but Erlang distribution failed
secondary: * suggestion: hostname mismatch?
secondary: * suggestion: is the cookie set correctly?
secondary:
secondary: current node details:
secondary: - node name: 'rabbitmq-cli-1781@secondary'
secondary: - home dir: /var/lib/rabbitmq
secondary: - cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
secondary: Resetting node rabbit@secondary ...
secondary: Error: unable to connect to node rabbit@secondary: nodedown
secondary:
secondary: DIAGNOSTICS
secondary: ===========
secondary:
secondary: attempted to contact: [rabbit@secondary]
secondary:
secondary: rabbit@secondary:
secondary: * connected to epmd (port 4369) on secondary
secondary: * epmd reports node 'rabbit' running on port 25672
secondary: * TCP connection succeeded but Erlang distribution failed
secondary: * suggestion: hostname mismatch?
secondary: * suggestion: is the cookie set correctly?
secondary:
secondary: current node details:
secondary: - node name: 'rabbitmq-cli-1832@secondary'
secondary: - home dir: /var/lib/rabbitmq
secondary: - cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
secondary: Clustering node rabbit@secondary with rabbit@primary ...
secondary: Error: unable to connect to node rabbit@secondary: nodedown
secondary:
secondary: DIAGNOSTICS
secondary: ===========
secondary:
secondary: attempted to contact: [rabbit@secondary]
secondary:
secondary: rabbit@secondary:
secondary: * connected to epmd (port 4369) on secondary
secondary: * epmd reports node 'rabbit' running on port 25672
secondary: * TCP connection succeeded but Erlang distribution failed
secondary: * suggestion: hostname mismatch?
secondary: * suggestion: is the cookie set correctly?
secondary:
secondary: current node details:
secondary: - node name: 'rabbitmq-cli-1884@secondary'
secondary: - home dir: /var/lib/rabbitmq
secondary: - cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
secondary: Starting node rabbit@secondary ...
secondary: Error: unable to connect to node rabbit@secondary: nodedown
secondary:
secondary: DIAGNOSTICS
secondary: ===========
secondary:
secondary: attempted to contact: [rabbit@secondary]
secondary:
secondary: rabbit@secondary:
secondary: * connected to epmd (port 4369) on secondary
secondary: * epmd reports node 'rabbit' running on port 25672
secondary: * TCP connection succeeded but Erlang distribution failed
secondary: * suggestion: hostname mismatch?
secondary: * suggestion: is the cookie set correctly?
secondary:
secondary: current node details:
secondary: - node name: 'rabbitmq-cli-1935@secondary'
secondary: - home dir: /var/lib/rabbitmq
secondary: - cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
Looks like the node name is not configured properly, as here is what I see if I ssh in the secondary node using vagrant ssh secondary
:
root@secondary:~# rabbitmqctl stop
Stopping and halting node rabbit@secondary ...
Error: unable to connect to node rabbit@secondary: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@secondary]
rabbit@secondary:
* connected to epmd (port 4369) on secondary
* epmd reports node 'rabbit' running on port 25672
* TCP connection succeeded but Erlang distribution failed
* suggestion: hostname mismatch?
* suggestion: is the cookie set correctly?
current node details:
- node name: 'rabbitmq-cli-2166@secondary'
- home dir: /var/lib/rabbitmq
- cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
Here is how the /var/log/rabbitmq/ folder's content looks like:
root@secondary:~# ll /var/log/rabbitmq/
total 24
drwxr-xr-x 2 rabbitmq rabbitmq 4096 Mar 24 2015 ./
drwxrwxr-x 10 root syslog 4096 Sep 22 16:04 ../
-rw-r--r-- 1 rabbitmq rabbitmq 7187 Sep 22 16:04 [email protected]
-rw-r--r-- 1 rabbitmq rabbitmq 0 Mar 24 2015 [email protected]
-rw-r--r-- 1 root root 0 Mar 24 2015 shutdown_err
-rw-r--r-- 1 root root 64 Mar 24 2015 shutdown_log
-rw-r--r-- 1 rabbitmq rabbitmq 0 Sep 22 16:22 startup_err
-rw-r--r-- 1 rabbitmq rabbitmq 62 Sep 22 16:22 startup_log
I was expecting the see the log file names to be '[email protected]' etc.
And here are the top 10 lines from the log file, which shows the node name (in bold below):
root@secondary:~# head /var/log/rabbitmq/[email protected]
=INFO REPORT==== 24-Mar-2015::02:08:07 ===
Starting RabbitMQ 3.5.0 on Erlang 17.4
Copyright (C) 2007-2014 GoPivotal, Inc.
Licensed under the MPL. See http://www.rabbitmq.com/
=INFO REPORT==== 24-Mar-2015::02:08:07 ===
**node : rabbit@vagrant-ubuntu-trusty-64**
home dir : /var/lib/rabbitmq
config file(s) : /etc/rabbitmq/rabbitmq.config (not found)
This command also confirms the node name mismatch:
root@secondary:~# rabbitmqctl start_app
Starting node rabbit@secondary ...
Error: unable to connect to node rabbit@secondary: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@secondary]
rabbit@secondary:
* connected to epmd (port 4369) on secondary
* epmd reports node 'rabbit' running on port 25672
* TCP connection succeeded but Erlang distribution failed
* suggestion: hostname mismatch?
* suggestion: is the cookie set correctly?
current node details:
- node name: 'rabbitmq-cli-2779@secondary'
- home dir: /var/lib/rabbitmq
- cookie hash: H6gXPXlo+GZy8pWfFX3Ynw==
Also attempted to restart the service:
root@secondary:~# service rabbitmq-server stop
* Stopping message broker rabbitmq-server * message broker already stopped
[ OK ]
root@secondary:~# service rabbitmq-server start
* Starting message broker rabbitmq-server * FAILED - check /var/log/rabbitmq/startup_\{log, _err\}
[fail]
root@secondary:~# cat /var/log/rabbitmq/startup_log
ERROR: node with name "rabbit" already running on "secondary"
root@secondary:~# cat /var/log/rabbitmq/startup_err
root@secondary:~#
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.