Java Code Examples for javax.jms.BytesMessage#setObjectProperty()
The following examples show how to use
javax.jms.BytesMessage#setObjectProperty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsClient.java From ats-framework with Apache License 2.0 | 6 votes |
private void doSendBinaryMessage( final Session session, final Destination destination, final byte[] bytes, final Map<String, ?> properties ) throws JMSException { try { BytesMessage message = session.createBytesMessage(); message.writeBytes(bytes); if (properties != null) { // Note: Setting any properties (including JMS fields) using // setObjectProperty might not be supported by all providers // Tested with: ActiveMQ for (final Entry<String, ?> property : properties.entrySet()) { message.setObjectProperty(property.getKey(), property.getValue()); } } final MessageProducer producer = session.createProducer(destination); producer.send(message); } finally { releaseSession(false); } }
Example 2
Source File: ReSendMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testResendWithLargeMessage() throws Exception { conn = cf.createConnection(); conn.start(); Session sess = conn.createSession(true, Session.SESSION_TRANSACTED); ArrayList<Message> msgs = new ArrayList<>(); for (int i = 0; i < 10; i++) { BytesMessage bm = sess.createBytesMessage(); bm.setObjectProperty(ActiveMQJMSConstants.JMS_ACTIVEMQ_INPUT_STREAM, ActiveMQTestBase.createFakeLargeStream(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE)); msgs.add(bm); MapMessage mm = sess.createMapMessage(); mm.setBoolean("boolean", true); mm.setByte("byte", (byte) 3); mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5}); mm.setChar("char", (char) 6); mm.setDouble("double", 7.0); mm.setFloat("float", 8.0f); mm.setInt("int", 9); mm.setLong("long", 10L); mm.setObject("object", new String("this is an object")); mm.setShort("short", (short) 11); mm.setString("string", "this is a string"); msgs.add(mm); msgs.add(sess.createTextMessage("hello" + i)); msgs.add(sess.createObjectMessage(new SomeSerializable("hello" + i))); } internalTestResend(msgs, sess); }
Example 3
Source File: JMSLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testSimpleLargeMessage() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = session.createProducer(queue1); BytesMessage m = session.createBytesMessage(); m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(1024 * 1024)); prod.send(m); conn.close(); conn = cf.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = session.createConsumer(queue1); conn.start(); BytesMessage rm = (BytesMessage) cons.receive(10000); byte[] data = new byte[1024]; for (int i = 0; i < 1024 * 1024; i += 1024) { int numberOfBytes = rm.readBytes(data); Assert.assertEquals(1024, numberOfBytes); for (int j = 0; j < 1024; j++) { Assert.assertEquals(ActiveMQTestBase.getSamplebyte(i + j), data[j]); } } Assert.assertNotNull(rm); }
Example 4
Source File: JMSLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testSimpleLargeMessage2() throws Exception { conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = session.createProducer(queue1); BytesMessage m = session.createBytesMessage(); m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(10)); prod.send(m); conn.close(); conn = cf.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = session.createConsumer(queue1); conn.start(); BytesMessage rm = (BytesMessage) cons.receive(10000); byte[] data = new byte[1024]; int numberOfBytes = rm.readBytes(data); Assert.assertEquals(10, numberOfBytes); for (int j = 0; j < numberOfBytes; j++) { Assert.assertEquals(ActiveMQTestBase.getSamplebyte(j), data[j]); } Assert.assertNotNull(rm); }
Example 5
Source File: JMSLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
@Test public void testWaitOnOutputStream() throws Exception { int msgSize = 1024 * 1024; conn = cf.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer prod = session.createProducer(queue1); BytesMessage m = session.createBytesMessage(); m.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(msgSize)); prod.send(m); conn.close(); conn = cf.createConnection(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer cons = session.createConsumer(queue1); conn.start(); BytesMessage rm = (BytesMessage) cons.receive(10000); Assert.assertNotNull(rm); final AtomicLong numberOfBytes = new AtomicLong(0); final AtomicInteger numberOfErrors = new AtomicInteger(0); OutputStream out = new OutputStream() { int position = 0; @Override public void write(final int b) throws IOException { numberOfBytes.incrementAndGet(); if (ActiveMQTestBase.getSamplebyte(position++) != b) { instanceLog.warn("Wrong byte at position " + position); numberOfErrors.incrementAndGet(); } } }; try { rm.setObjectProperty("JMS_AMQ_InputStream", ActiveMQTestBase.createFakeLargeStream(100)); Assert.fail("Exception expected!"); } catch (MessageNotWriteableException expected) { } rm.setObjectProperty("JMS_AMQ_SaveStream", out); Assert.assertEquals(msgSize, numberOfBytes.get()); Assert.assertEquals(0, numberOfErrors.get()); }