<dependencies>
...
<dependency>
<groupId>org.appsensor</groupId>
<artifactId>appsensor-amqp-rabbitmq-client</artifactId>
<version>1.0.0</version>
</dependency>
...
</dependencies>
properties
rabbitmq.host=127.0.0.1
rabbitmq.port=5672
rabbitmq.username=guest
rabbitmq.password=guest
import org.appsensor.amqp.rabbitmq.AmqpUtil;
public class AppSensorClient {
public static void main(String[] args) {
AmqpUtil.sendToQueue("appsensor.events", message.getBytes());
}
}
import com.rabbitmq.client.*;
public class AppSensorServer {
private final static String QUEUE_NAME = "appsensor.events";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
factory.setUsername("guest");
factory.setPassword("guest");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
Consumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body)
throws IOException {
String message = new String(body, "UTF-8");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
}