List of usage examples for com.rabbitmq.client GetResponse getBody
public byte[] getBody()
From source file:joram.amqp.PersistenceSimpleTest.java
License:Open Source License
public void recover1() throws Exception { ConnectionFactory cnxFactory = new ConnectionFactory(); Connection connection = cnxFactory.newConnection(); Channel channel = connection.createChannel(); DeclareOk declareOk = channel.queueDeclare("testqueue", true, false, false, null); channel.txSelect();/*from w w w. j a v a 2s . co m*/ for (int i = 0; i < 5; i++) { channel.basicPublish("", declareOk.getQueue(), MessageProperties.PERSISTENT_BASIC, "this is a test message !!!".getBytes()); } channel.txCommit(); killAgentServer((short) 0); startAgentServer((short) 0); connection = cnxFactory.newConnection(); channel = connection.createChannel(); declareOk = channel.queueDeclarePassive("testqueue"); for (int i = 0; i < 5; i++) { GetResponse msg = channel.basicGet("testqueue", true); assertNotNull(msg); assertEquals("this is a test message !!!", new String(msg.getBody())); } GetResponse msg = channel.basicGet("testqueue", true); assertNull(msg); channel.queueDelete(declareOk.getQueue()); }
From source file:lfp.rabbitmq.presence.tests.PresenceTests.java
License:Mozilla Public License
public Map<String, Object> getPresenceHeaders(String qname) throws IOException { GetResponse r = basicGet(qname); assertNotNull("Expected a presence message", r); byte[] body = r.getBody(); if (body != null && body.length > 0) { fail("Expected null or empty body in presence message"); }/*from w w w. ja v a 2 s . c om*/ Map<String, Object> h = r.getProps().getHeaders(); assertNotNull("Expected headers in presence message", h); return h; }
From source file:lfp.rabbitmq.udpexchange.tests.UdpExchangeTests.java
License:Mozilla Public License
public void testUdpSendAmqpReceive() throws IOException { String message = "Hello from UDP"; sendString(message, pOutRaw);//from w ww. ja va2s .c o m GetResponse r = basicGet(q1); assertNotNull(r); assertEquals(message, new String(r.getBody(), "utf-8")); }
From source file:lfp.rabbitmq.udpexchange.tests.UdpExchangeTests.java
License:Mozilla Public License
public void checkReceivedStompDelivery(String expectedRKSuffix) throws IOException { GetResponse r = basicGet(q1); assertNotNull(r);/*from w w w . ja v a 2 s . c o m*/ assertTrue("Delivery has correct routing key", r.getEnvelope().getRoutingKey().endsWith(expectedRKSuffix)); assertEquals("rk1", r.getProps().getHeaders().get("destination").toString()); assertEquals("rk2", r.getProps().getHeaders().get("rk").toString()); assertEquals("value1", r.getProps().getHeaders().get("header1").toString()); assertEquals("value2", r.getProps().getHeaders().get("header2").toString()); assertEquals("Hello STOMP", new String(r.getBody(), "utf-8")); }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void prePutHappyCase() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", ""); setupHBase(kvs);/*w ww . j a va2 s . co m*/ //simulate population of secondary index as a result of the above Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); // Add a column to the primary table, which should trigger a data ripple to the downstream table Put tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); //check that values made it to the queue com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); System.out.println(String.format("Test: connecting to %s", primaryTableNameString)); while (true) { GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null)//busy-wait until the message has made it through the MQ { continue; } String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString()); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_family = (String) jo.get("column_family"); Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family); String column_value = (String) jo.get("column_value"); Assert.assertEquals("Column value should be preserved in the message body", "some_value", column_value); long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); break; } }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void verifyValueNotSentByDefault() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "false", ""); setupHBase(kvs);//from ww w . ja va2 s. co m //simulate population of secondary index as a result of the above Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); // Add a column to the primary table, which should trigger a data ripple to the downstream table Put tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); //check that values made it to the queue com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); System.out.println(String.format("Test: connecting to %s", primaryTableNameString)); while (true) { GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null)//busy-wait until the message has made it through the MQ { continue; } String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString()); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_family = (String) jo.get("column_family"); Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family); String column_value = (String) jo.get("column_value"); Assert.assertEquals("Column value is not sent by default", "", column_value); long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); break; } }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void filterOnQualifiers() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "false", "one_key|some_key"); setupHBase(kvs);/*w w w . j a va 2 s.c o m*/ //simulate population of secondary index as a result of the above Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); // Add a column to the primary table, which should trigger a data ripple to the downstream table Put tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); //check that values made it to the queue com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); System.out.println(String.format("Test: connecting to %s", primaryTableNameString)); while (true) { GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null)//busy-wait until the message has made it through the MQ { continue; } String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString()); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_family = (String) jo.get("column_family"); Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family); String column_value = (String) jo.get("column_value"); Assert.assertEquals("Column value is not sent by default", "", column_value); long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); break; } }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void onlyPutWhenInQualifierFilter() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "false", "some_key"); setupHBase(kvs);/*from w ww . ja v a2 s . c o m*/ //simulate population of secondary index as a result of the above Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); // Add a column to the primary table, which should trigger a data ripple to the downstream table Put tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes()); tablePut.addColumn("e".getBytes(), "other_key".getBytes(), "some_value".getBytes()); tablePut.addColumn("e".getBytes(), "third_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); //check that values made it to the queue com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); System.out.println(String.format("Test: connecting to %s", primaryTableNameString)); while (true) { int numMessages = channel.queueDeclarePassive(primaryTableNameString).getMessageCount(); GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null || numMessages == 0)//busy-wait until the message has made it through the MQ { continue; } Assert.assertEquals("There should be only a single key in the queue", 1, numMessages); String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); Assert.assertEquals("An action should be set on the message", "put", headers.get("action").toString()); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_family = (String) jo.get("column_family"); Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family); String column_value = (String) jo.get("column_value"); Assert.assertEquals("Column value is not sent by default", "", column_value); long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); break; } }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void preDeleteHappyCase() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", ""); setupHBase(kvs);/*from w w w.ja va2s . c o m*/ com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); //simulate population of secondary index for a put on the downstreamTable Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); //simulate a data rippling performed by the data_rippler service consuming off of the rabbitmq queue Put tablePut = new Put("EFB1".getBytes()); tablePut.addColumn("eg".getBytes(), "some_key".getBytes(), "some_value".getBytes()); downstreamTable.put(tablePut); // since we made no active put to the queue from the prePut, we need to declare it explicitly here channel.queueDeclare(primaryTableNameString, true, false, false, null); // finished with the setup, we now issue a delete which should be caught by the rabbitmq Delete d = new Delete("EFG1".getBytes()); primaryTable.delete(d); //check that values made it to the queue while (true) { GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null)//busy-wait until the message has made it through the MQ { continue; } String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); Assert.assertEquals("An action should be set on the message", "delete", headers.get("action").toString()); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_qualifier = (String) jo.get("column_qualifier"); Assert.assertEquals("Column qualifier should be empty, signalling a row delete", "", column_qualifier); long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); break; } }
From source file:net.nzcorp.hbase.tableevent_signaler.TableEventSignalerTest.java
License:Apache License
@Test public void discernNewPutFromUpdate() throws Exception { Map<String, String> kvs = configureHBase(primaryTableNameString, secondaryIdxTableNameString, "e", "eg", "a", amq_default_address, primaryTableNameString, "true", ""); setupHBase(kvs);//from ww w. j a v a2s. c o m //simulate population of secondary index as a result of the above Put idxPut = new Put("EFG1".getBytes()); idxPut.addColumn("a".getBytes(), "EFB1".getBytes(), "".getBytes()); secondaryIdxTable.put(idxPut); /* The first put should be registered as a "put" action, while the second should be registered as an "update" action, thereby signalling different action to be taken by the consumers */ Put tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); tablePut = new Put("EFG1".getBytes()); tablePut.addColumn("e".getBytes(), "some_other_key".getBytes(), "some_value".getBytes()); primaryTable.put(tablePut); //check that values made it to the queue com.rabbitmq.client.ConnectionFactory factory = new com.rabbitmq.client.ConnectionFactory(); factory.setUri(amq_default_address); com.rabbitmq.client.Connection conn = factory.newConnection(); com.rabbitmq.client.Channel channel = conn.createChannel(); int msgs_to_consume = 2; while (msgs_to_consume > 0) { System.out.println(String.format("Messages to get: %s", msgs_to_consume)); GetResponse response = channel.basicGet(primaryTableNameString, false); if (response == null)//busy-wait until the message has made it through the MQ { continue; } String routingKey = response.getEnvelope().getRoutingKey(); Assert.assertEquals("Routing key should be rowkey", "genome", routingKey); String contentType = response.getProps().getContentType(); Assert.assertEquals("Content type should be preserved", "application/json", contentType); Map<String, Object> headers = response.getProps().getHeaders(); byte[] body = response.getBody(); JSONObject jo = new JSONObject(new String(body)); String column_family = (String) jo.get("column_family"); Assert.assertEquals("Column family should be preserved in the message body", "eg", column_family); String column_value = (String) jo.get("column_qualifier"); if (headers.get("action").toString().equals("update")) { Assert.assertEquals("Column value should be preserved in the message body", "some_other_key", column_value); } else { Assert.assertEquals("Column value should be preserved in the message body", "some_key", column_value); } long deliveryTag = response.getEnvelope().getDeliveryTag(); channel.basicAck(deliveryTag, false); msgs_to_consume--; } }