Hello everybody,
I have an issue concerning rabbitmq
, I have just followed entirely this tutorial, Iam using rabbitmq management
on ubuntu
system, the problem is that messages never reach rabbitmq
endpoint, when I check via browser interface in localhost:15672
I can see that everything is good, the connections and channels are all there, but concerning queues there is any message there.
I have checked my code I didn’t any mistake, I have used the default exchange as mentionned in the tutorial so I just can’t debug this issue and maybe I have missed something.
Thank you in advance
It would help if you mention what version of a RabbitMQ library you are using, and to show some code.
Of course @dimitarvp ,
I have a docker instance of rabbitmq management
sudo docker run --rm -it --hostname abdelghani -p 15672:15672 -p 5672:5672 rabbitmq:3-management
The elixir code looks like
mix.exs:
....
{:amqp, "~> 3.3"}
...
rabbitmq.ex:
def subscribe(queue) do
{:ok, _connection, channel} = start_connection()
:ok = declare_queue(channel, queue)
:ok = consume(channel, queue)
:ok
end
def publish(queue, payload) do
:ok, connection, channel} = start_connection()
:ok = declare_queue(channel, queue)
:ok = produce(channel, queue, payload)
:ok = close_connection(connection)
:ok
end
def start_connection() do
{:ok, connection} = AMQP.Connection.open()
{:ok, channel} = AMQP.Channel.open(connection)
{:ok, connection, channel}
end
def declare_queue(channel, queue) do
AMQP.Queue.declare(channel, queue)
:ok
end
def consume(channel, queue) do
AMQP.Basic.consume(channel, queue, nil, no_ack: true)
:ok
end
def produce(channel, queue, payload) do
AMQP.Basic.publish(channel, "", queue, payload)
:ok
end
def close_connection(connection) do
AMQP.Connection.close(connection)
:ok
end
end
consumer.ex
:ok = Rabbitmq.subscribe("index")
producer.ex
payload = ....
:ok = Rabbitmq.publish("index", payload)
I can check in web interface that each call for subscribe
or publish
results in process connection to Rabbitmq server and a new channel created, but the queues are empty and there is no coming data.
I don’t know anything about this, but have you tried the exact code from the documentation, as it looks like you’ve missed a couple of steps: AMQP — amqp v3.3.0
Also, you always return :ok from your e.g. produce function instead of the result from the library module call, so you never know if it errors, despite matching it!
@ellispritchard thank you for your suggestions, I have shared a link to the source tutorial which I followed maybe you can take a look, I think it was official doc too from RabittMQ Foundation, also the returned :ok
is for ensuring successful of the call and in case of failure there will be an exception error and the process will exit…
I noticed that the issue is in passing message from elixir program to localhost rabbitmq, because if I have to send it manually to the exchange from rabbit UI then it will be broadcasted, I just wonder what is happening, I had never get this before
Finally, I found the bug, the payload was not a string
, I just wonder why AMQP
didn’t generate an exception and everything went in silence