Kdyby/RabbitMQ not sending any message

Notice: This thread is very old.
fronty
Member | 16
+
0
-

Hello,

I started to work with Kdyby\RabbitMQ according to this great post (in czech). After few my misunderstandings I was able to install and launch RabbitMQ server using rabbitmq-server and it's management plugin on http://localhost:15672/. I have also added Kdyby\Console plugin. Then I have added this configuration file:

# app/config/rabbitmq.neon
rabbitmq:
	connection:
		host: localhost
		port: 5672
		user: guest
		password: guest

	# Message producers
	producers:
		testBunny:
			exchange: {name: 'test-bunny', type: direct}
			queue: {name: 'test-bunny', deliveryMode: 2}
			contentType: application/json
			deliveryMode: 2
			autoSetupFabric: on

I have created a presenter, which should produce my first message:

<?php
...
/** @var \Kdyby\RabbitMq\Connection @inject */
public $rabbitmq;

public function actionDefault() {
	$producer = $this->rabbitmq->getProducer('testBunny');
	$producer->publish(json_encode(['greet' => "Hello %name", 'name' => "Bunny"]));
}
...
?>

Then I called default action accessing the presenter's URL in browser and was expecting, that some message will occur in RabbitMQ management as a peak in chart, but it didn't. Management plugin only gives me this:

  • 1 connection 127.0.0.1:56200, user guest, green state “running”
  • 1 channel 127.0.0.1:56200 (1), user guest, gray state “idle”
  • 9 exchanges including my test-bunny (type direct)
  • 1 queue test-bunny, gray state “idle”
  • 0 consumers

I tried to continue and add consumer definition to rabbitmq.neon:

# app/config/rabbitmq.neon
rabbitmq:
	...
	# Message consumers
	consumers:
		testBunny:
			exchange: {name: 'test-bunny', type: direct}
			queue: {name: 'test-bunny', deliveryMode: 2}
			callback: @App\Test\Test::process
			contentType: application/json
			deliveryMode: 2
			autoSetupFabric: on

services:
	- App\Test\Test

In App\Test\Test service I am only testing the received message using var_dump().
Eventually I have started the consumer to listen to new messages using php tenant/index.php rabbitmq:consumer testBunny --debug terminal command. Nothing was printed, neither did any debug data as in Filip's post. In RabbitMQ management I was only able to see my 1 consumer.

I tried to play with rabbitmq.neon configuration, from minimal to extended one I ended up with, but nothing helped. Tracy doesn't give me any error when accessing the presenter's default method, neither does the consumer in terminal.

I am running OS X 10.10.5 Yosemite, RabbitMQ server was installed using Homebrew, all Nette plugins using Composer.

Could any of you please give me the clue, what do I do wrong? Any kind of help is appreciated.

srigi
Nette Blogger | 558
+
0
-

Try run rabbitmq:setup-fabric on the console at the beginning. Then retry.

Last edited by srigi (2016-09-06 08:42)

fronty
Member | 16
+
0
-

The problem was, that I was expecting immediate output in terminal when running consumer script after I sent a message, but output is only written when I run the command with number of messages specified, like so:
php www/index.php rabbitmq:consumer testBunny -m 1 -d.

With this command, output is written immediately after sending a message and the consumer script ends it's listening.

This may only be the behavior of OS X Homebrew version of RabbitMQ. Without specifying the number of messages, output is not printed even after killing the process using Ctrl + C.

Does anyone know any workaround? Development is now a bit complicated, when I need to manually run consumer script every time I need to test the output.

srigi
Nette Blogger | 558
+
0
-

I'm using RabbitMQ powered by Docker for Mac. My messages get processed rightaway. Maybe try this platform. Running RabbitMQ is easy as

docker run -d --hostname develop -p 5672:5672 -p 15672:15672 --name rabbitmq-3.6 rabbitmq:3.6-management

This will start rmq on localhost:5672. On port 15672 you'll find management page.

fronty
Member | 16
+
0
-

Thanks a lot, srigi. In fact, I found RabbitMQ on Heroku website, because we want to move our application there, which includes Docker. I will definitely try Docker for Mac as you suggest.
Thanks a lot again.