RabbitMQ常见错误1

java.lang.IllegalStateException: Invalid configuration: ‘exchange’ must be non-null.
at com.rabbitmq.client.impl.AMQImpl$Basic$Publish.<init>(AMQImpl.java:2278)
at com.rabbitmq.client.AMQP$Basic$Publish$Builder.build(AMQP.java:1219)
at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:691)
at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:668)
at com.rabbitmq.client.impl.ChannelN.basicPublish(ChannelN.java:658)
at com.rabbitmq.client.impl.recovery.AutorecoveringChannel.basicPublish(AutorecoveringChannel.java:192)
at com.xuecheng.test.rabbitmq.RabbitMqProducerTest.main(RabbitMqProducerTest.java:60)

// 发送消息
/*
String var1, String var2, BasicProperties var3, byte[] var4
参数明细:
1.交换机:如果不指定将使用mq的默认交换机,(设置为 '')
2.路由key,交换机根据路由key来将消息转发到指定的队列,如果使用默认交换机,routingkey设置为队列的名称
3.消息的属性
4.消息内容
*/
String message = "Hello,RabbitMQ...学成在线";
channel.basicPublish(null,QUEUE,null,message.getBytes());// 如果不设置交换机,会使用默认的交换机,不能设置为null
System.out.println("send mq:"+message);