package
com.xx;
/**
* Created by xx on 2017/6/19.
*/
import
com.rabbitmq.client.ConnectionFactory;
import
com.rabbitmq.client.Connection;
import
com.rabbitmq.client.Channel;
import
java.io.IOException;
import
java.util.concurrent.TimeoutException;
public
class
SendMQ {
private
final
static
String QUEUE_NAMA=
"queue_name"
;
public
static
void
main(String[] args)
throws
IOException, TimeoutException {
ConnectionFactory factory =
new
ConnectionFactory();
factory.setHost(
"10.1.1.1"
);
factory.setUsername(
"xx"
);
factory.setPassword(
"xx@123"
);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAMA,
false
,
false
,
false
,
null
);
String message =
"hello world"
;
channel.basicPublish(
""
,QUEUE_NAMA,
null
,message.getBytes());
System.out.println(
"[x] Send '"
+ message +
"'"
);
channel.close();
connection.close();
}
}