1,python调用MQ发送消息(生产者),话不多说,直接上干货
import pika
如下图
2.java调用MQ发送消息(生产者)
具体代码如下:
python 的代码如下
connection = pika.BlockingConnection(pika.ConnectionParameters('IP',端口,'/'))
channel =connection.channel()
msg_props = pika.BasicProperties()
msg_props.content_type="text/plain"
channel.basic_publish(exchange='EXCHANGE_ORDER_NEW',routing_key='QUEUE_WECHAT_ORDER',body='数据信息',properties=msg_props)
connection.close()
java调用MQ的代码如下:
ConnectionFactory factory=new ConnectionFactory();
factory.setHost("IP地址");
factory.setPort(1111);
Connection connection=factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare("设置队列队列名_NEW", false, false, false, null);
String message="要发送的消息";
BasicProperties properties = new BasicProperties("text", null, null, null, null, null, null, null, null, null, null, null, null, null);
channel.basicPublish("设置队列队列名_NEW", "队列名", properties, message.getBytes("UTF-8"));
channel.close();
connection.close();