use of com.rabbitmq.client.Envelope in project uavstack by uavorg.
the class TestRestService method testRabbitmq.
@GET
@Path("testRabbitmq")
public void testRabbitmq(String jsonString) {
String QUEUE_NAME = "haha";
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("127.0.0.1");
factory.setPort(5672);
try {
com.rabbitmq.client.Connection conn = factory.newConnection();
Channel channel = conn.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(" [x] Sent '" + message + "'");
channel.close();
conn.close();
com.rabbitmq.client.Connection connection = factory.newConnection();
Channel recvchannel = connection.createChannel();
recvchannel.queueDeclare(QUEUE_NAME, false, false, false, null);
com.rabbitmq.client.Consumer consumer = new DefaultConsumer(recvchannel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
String message = new String(body, "UTF-8");
// System.out.println(" [x] Received '" + message + "'1");
}
};
recvchannel.basicConsume(QUEUE_NAME, true, consumer);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
use of com.rabbitmq.client.Envelope in project uavstack by uavorg.
the class RabbitMQRecv method send.
@POST
@Path("rabbitmqRecv")
public void send() throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername("guest");
factory.setPassword("guest");
factory.setHost("127.0.0.1");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
DefaultConsumer consumer = new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
System.out.println(properties.getHeaders());
String message = new String(body, "UTF-8");
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
use of com.rabbitmq.client.Envelope in project rabbitmq-queue-management by gessnerfl.
the class MessageMapperTest method shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInMap.
@Test
public void shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeadersDeepInMap() {
String headerKey = "headerKey";
String subHeaderKey = "subHeaderKey";
String subHeaderValue = "subHeaderValue";
LongString longStringValue = mock(LongString.class);
when(longStringValue.toString()).thenReturn(subHeaderValue);
Map<String, Object> subHeaders = new HashMap<>();
subHeaders.put(subHeaderKey, longStringValue);
Map<String, Object> headers = new HashMap<>();
headers.put(headerKey, subHeaders);
AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
when(basicProperties.getHeaders()).thenReturn(headers);
Envelope envelope = mock(Envelope.class);
GetResponse getResponse = mockResponse(envelope, basicProperties);
Message result = sut.map(getResponse);
BasicProperties basicPropertiesOfResult = result.getProperties();
assertNotNull(basicPropertiesOfResult);
assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
assertThat(basicPropertiesOfResult.getHeaders().get(headerKey), Matchers.instanceOf(Map.class));
assertThat(((Map<String, Object>) basicPropertiesOfResult.getHeaders().get(headerKey)).keySet(), Matchers.hasSize(1));
assertThat(((Map<String, Object>) basicPropertiesOfResult.getHeaders().get(headerKey)), Matchers.hasKey(subHeaderKey));
assertEquals(subHeaderValue, ((Map) basicPropertiesOfResult.getHeaders().get(headerKey)).get(subHeaderKey));
}
use of com.rabbitmq.client.Envelope in project rabbitmq-queue-management by gessnerfl.
the class MessageMapperTest method shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeaders.
@Test
public void shouldMapRabbitMqSpecificTypesInAmqpBasicPropertiesHeaders() {
String headerKey = "headerKey";
String headerValue = "headerValue";
LongString longStringValue = mock(LongString.class);
when(longStringValue.toString()).thenReturn(headerValue);
Map<String, Object> headers = new HashMap<>();
headers.put(headerKey, longStringValue);
AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
when(basicProperties.getHeaders()).thenReturn(headers);
Envelope envelope = mock(Envelope.class);
GetResponse getResponse = mockResponse(envelope, basicProperties);
Message result = sut.map(getResponse);
BasicProperties basicPropertiesOfResult = result.getProperties();
assertNotNull(basicPropertiesOfResult);
assertThat(basicPropertiesOfResult.getHeaders().keySet(), Matchers.hasSize(1));
assertThat(basicPropertiesOfResult.getHeaders(), Matchers.hasKey(headerKey));
assertEquals(headerValue, basicPropertiesOfResult.getHeaders().get(headerKey));
}
use of com.rabbitmq.client.Envelope in project rabbitmq-queue-management by gessnerfl.
the class MessageMapperTest method shouldMapBasicMessageFields.
@Test
public void shouldMapBasicMessageFields() {
String checksum = "checksum";
Envelope envelope = mock(Envelope.class);
AMQP.BasicProperties basicProperties = mock(AMQP.BasicProperties.class);
GetResponse getResponse = mockResponse(envelope, basicProperties);
when(messageChecksum.createFor(basicProperties, DEFAULT_PAYLOAD)).thenReturn(checksum);
Message result = sut.map(getResponse);
assertEquals(DEFAULT_PAYLOAD, result.getBody());
assertEquals(checksum, result.getChecksum());
assertSame(envelope, result.getEnvelope());
assertNotNull(result.getProperties());
}
Aggregations