Search in sources :

Example 1 with RMQObjectMessage

use of com.rabbitmq.jms.client.message.RMQObjectMessage in project rabbitmq-jms-client by rabbitmq.

the class TestWhiteListObjectSerialization method expectSuccessWith.

private void expectSuccessWith(List<String> prefixes) throws JMSException {
    TestKlazz k = new TestKlazz("abc");
    RMQObjectMessage om = new RMQObjectMessage();
    om.setObject(k);
    RMQObjectMessage.recreate(om, prefixes);
}
Also used : RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage)

Example 2 with RMQObjectMessage

use of com.rabbitmq.jms.client.message.RMQObjectMessage in project rocketmq-externals by apache.

the class RabbitmqSourceTaskTest method getMessageConnentTest.

@Test
public void getMessageConnentTest() throws JMSException {
    String value = "hello rocketmq";
    RabbitmqSourceTask task = new RabbitmqSourceTask();
    RMQTextMessage textMessage = new RMQTextMessage();
    textMessage.setText(value);
    ByteBuffer buffer = task.getMessageContent(textMessage);
    Assert.assertEquals(new String(buffer.array()), textMessage.getText());
    ObjectMessage objectMessage = new RMQObjectMessage();
    objectMessage.setObject(value);
    buffer = task.getMessageContent(objectMessage);
    Assert.assertEquals(new String(buffer.array()), "\"" + objectMessage.getObject().toString() + "\"");
    BytesMessage bytes = new RMQBytesMessage();
    bytes.writeBytes(value.getBytes());
    bytes.reset();
    buffer = task.getMessageContent(bytes);
    Assert.assertEquals(new String(buffer.array()), value);
    MapMessage mapMessage = new RMQMapMessage();
    mapMessage.setString("hello", "rocketmq");
    buffer = task.getMessageContent(mapMessage);
    Map<String, String> map = JSON.parseObject(buffer.array(), Map.class);
    Assert.assertEquals(map.get("hello"), "rocketmq");
    Assert.assertEquals(map.size(), 1);
    StreamMessage streamMessage = new RMQStreamMessage();
    String valueTwo = null;
    for (int i = 0; i < 200; i++) {
        valueTwo = valueTwo + value;
    }
    streamMessage.writeBytes(valueTwo.getBytes());
    streamMessage.reset();
// buffer = task.getMessageContent(streamMessage);
// Assert.assertEquals(new String(buffer.array()), valueTwo);
}
Also used : MapMessage(javax.jms.MapMessage) RMQMapMessage(com.rabbitmq.jms.client.message.RMQMapMessage) RMQTextMessage(com.rabbitmq.jms.client.message.RMQTextMessage) RMQBytesMessage(com.rabbitmq.jms.client.message.RMQBytesMessage) BytesMessage(javax.jms.BytesMessage) ByteBuffer(java.nio.ByteBuffer) RMQMapMessage(com.rabbitmq.jms.client.message.RMQMapMessage) RMQStreamMessage(com.rabbitmq.jms.client.message.RMQStreamMessage) RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) ObjectMessage(javax.jms.ObjectMessage) RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) RMQStreamMessage(com.rabbitmq.jms.client.message.RMQStreamMessage) StreamMessage(javax.jms.StreamMessage) RMQBytesMessage(com.rabbitmq.jms.client.message.RMQBytesMessage) Test(org.junit.Test)

Example 3 with RMQObjectMessage

use of com.rabbitmq.jms.client.message.RMQObjectMessage in project rabbitmq-jms-client by rabbitmq.

the class ObjectMessageSerializationIT method testReceiveObjectMessageWithPayload.

protected void testReceiveObjectMessageWithPayload(Object payload) throws Exception {
    try {
        queueConn.start();
        QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
        Queue queue = queueSession.createQueue(QUEUE_NAME);
        drainQueue(queueSession, queue);
        QueueSender queueSender = queueSession.createSender(queue);
        queueSender.send(MessageTestType.OBJECT.gen(queueSession, (Serializable) payload));
    } finally {
        reconnect(Arrays.asList("java.lang", "com.rabbitmq.jms"));
    }
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(QUEUE_NAME);
    QueueReceiver queueReceiver = queueSession.createReceiver(queue);
    RMQObjectMessage m = (RMQObjectMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
    assertEquals(m.getObject(), payload);
    assertEquals(m.getObject(TRUSTED_PACKAGES), payload);
}
Also used : RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) Serializable(java.io.Serializable) QueueSender(javax.jms.QueueSender) QueueReceiver(javax.jms.QueueReceiver) Queue(javax.jms.Queue) QueueSession(javax.jms.QueueSession)

Example 4 with RMQObjectMessage

use of com.rabbitmq.jms.client.message.RMQObjectMessage in project rabbitmq-jms-client by rabbitmq.

the class TestWhiteListObjectSerialization method expecteFailureWith.

private void expecteFailureWith(List<String> patterns, TestKlazz serializedValue) throws JMSException {
    RMQObjectMessage om = new RMQObjectMessage();
    om.setObject(serializedValue);
    try {
        RMQObjectMessage.recreate(om, patterns);
        fail("Expected an exception");
    } catch (JMSException ignored) {
    }
}
Also used : RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) JMSException(javax.jms.JMSException)

Example 5 with RMQObjectMessage

use of com.rabbitmq.jms.client.message.RMQObjectMessage in project rabbitmq-jms-client by rabbitmq.

the class TestWhiteListObjectSerialization method testSuccessWithPrimitiveTypes.

@Test
public void testSuccessWithPrimitiveTypes() throws IOException, JMSException {
    RMQObjectMessage om = new RMQObjectMessage();
    om.setObject("JMS");
    RMQObjectMessage.recreate(om, Collections.singletonList("/does/not/match/any/package"));
}
Also used : RMQObjectMessage(com.rabbitmq.jms.client.message.RMQObjectMessage) Test(org.junit.jupiter.api.Test)

Aggregations

RMQObjectMessage (com.rabbitmq.jms.client.message.RMQObjectMessage)5 RMQBytesMessage (com.rabbitmq.jms.client.message.RMQBytesMessage)1 RMQMapMessage (com.rabbitmq.jms.client.message.RMQMapMessage)1 RMQStreamMessage (com.rabbitmq.jms.client.message.RMQStreamMessage)1 RMQTextMessage (com.rabbitmq.jms.client.message.RMQTextMessage)1 Serializable (java.io.Serializable)1 ByteBuffer (java.nio.ByteBuffer)1 BytesMessage (javax.jms.BytesMessage)1 JMSException (javax.jms.JMSException)1 MapMessage (javax.jms.MapMessage)1 ObjectMessage (javax.jms.ObjectMessage)1 Queue (javax.jms.Queue)1 QueueReceiver (javax.jms.QueueReceiver)1 QueueSender (javax.jms.QueueSender)1 QueueSession (javax.jms.QueueSession)1 StreamMessage (javax.jms.StreamMessage)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1