package com.basic.security.utils;
|
|
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Connection;
|
import com.rabbitmq.client.ConnectionFactory;
|
|
public class RabbitMQProducer {
|
static String QUEUE_NAME = "alarm2Android";
|
static ConnectionFactory factory = new ConnectionFactory();
|
|
public static void init() {
|
try {
|
ConnectionFactory factory = new ConnectionFactory();
|
factory.setHost("localhost");
|
Connection connection = factory.newConnection();
|
Channel channel = connection.createChannel();
|
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
|
String message = "Hello World!";
|
channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
|
System.out.println("P [x] Sent '" + message + "'");
|
channel.close();
|
connection.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
public static void main(String[] args) {
|
init();
|
}
|
|
}
|