Node Js:我创建了一个带有nodejs和socket的用户,用于与之通信 rabbitMq和symfony
var http = require('http'),
url = require('url'),
amqp = require('amqplib/callback_api');
amqp.connect('amqp://user:pass@192.168.99.10:55672', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'hello';
ch.assertQueue(q, {durable: false});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) {
console.log(" [x] Received %s", msg.content.toString());
}, {noAck: true});
});
});
var server = require('http').createServer();
var io = require('socket.io')(server);
io.on('connection', function(client){
console.log('here');
client.on('event', function(data){});
client.on('disconnect', function(){});
});
server.listen(3000);
Symfony 3
我用symfony 3创建了一个Producer
ProducerController
class ProducerController extends Controller
{
/**
* @Route("/producer", name="producer")
*/
public function uploadAction(Request $request)
{
$userId = mt_rand(1, 1000000);
$message = \Swift_Message::newInstance()
->setSubject('Sujet de l\'email')
->setFrom('test@xxx.com')
->setTo('destinaire@xxx.com')
->setBody($this->renderView('index.html.twig', ['userId' =>$userId]), 'text/html');
$this->get('old_sound_rabbit_mq.message_producer')->publish(serialize($message));
return $this->render('welcome.html.twig', ['userId' => $userId]);
}
}
config.yml
old_sound_rabbit_mq:
connections:
default:
host: '192.168.99.10' # hostname and port of the rabbitmq server
port: 55672
user: 'user'
password: 'pass'
vhost: '/'
lazy: true # a lazy connection avoids unnecessary connections to the broker on every request
producers:
message:
connection: default # connects to the default connection configured above
exchange_options: {name: 'message', type: direct}
现在问题是我不知道如何与生产者和消费者沟通。 node consumer.js执行normal并等待消息 node app.js它没有显示任何内容