use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class MessageTypeTest method testBytesMessage_1.
/**
* Send a <code>BytesMessage</code> with an empty body.
* <br />
* Receive it and test if the message is effectively an instance of
* <code>BytesMessage</code>
*/
@Test
public void testBytesMessage_1() {
try {
BytesMessage message = senderSession.createBytesMessage();
sender.send(message);
Message msg = receiver.receive(TestConfig.TIMEOUT);
Assert.assertTrue("The message should be an instance of BytesMessage.\n", msg instanceof BytesMessage);
} catch (JMSException e) {
fail(e);
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class ReplicationFlowControlTest method internalTest.
private void internalTest(boolean failover) throws Exception {
int KILL_SERVER = failover ? 50_000 : -1;
Connection connection = null;
try {
server0 = startServer(SERVER_NAME_0, 0, 30000);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connection = connectionFactory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue("exampleQueue");
MessageProducer producer = session.createProducer(queue);
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(new byte[20 * 1024]);
for (int i = 0; i < NUM_MESSAGES; i++) {
producer.send(bytesMessage);
if (i % 1000 == 0) {
System.out.println("Sent " + i + " messages, consumed=" + totalConsumed.get());
session.commit();
}
if (i == START_CONSUMERS) {
System.out.println("Starting consumers");
// if failover, no AMQP
startConsumers(!failover);
}
if (KILL_SERVER >= 0 && i == KILL_SERVER) {
session.commit();
System.out.println("Killing server");
ServerUtil.killServer(server0);
Thread.sleep(2000);
connection.close();
connection = connectionFactory.createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue("exampleQueue");
producer = session.createProducer(queue);
}
if (i == START_SERVER) {
System.out.println("Starting extra server");
server1 = startServer(SERVER_NAME_1, 0, 30000);
}
}
session.commit();
System.out.println("Awaiting all consumers to finish");
while (!latch.await(10, TimeUnit.SECONDS)) {
fail("couldn't receive all messages");
}
running.set(false);
for (Consumer consumer : consumers) {
consumer.join(10000);
if (consumer.isAlive()) {
consumer.interrupt();
}
}
} finally {
running.set(false);
if (connection != null) {
connection.close();
}
for (Consumer consumer : consumers) {
consumer.interrupt();
consumer.join();
}
}
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class StompTest method testSendMessageWithContentLength.
@Test
public void testSendMessageWithContentLength() throws Exception {
MessageConsumer consumer = session.createConsumer(queue);
conn.connect(defUser, defPass);
byte[] data = new byte[] { 1, 0, 0, 4 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(data);
baos.flush();
ClientStompFrame frame = conn.createFrame(Stomp.Commands.SEND).addHeader(Stomp.Headers.Send.DESTINATION, getQueuePrefix() + getQueueName()).addHeader(Stomp.Headers.CONTENT_LENGTH, Integer.toString(data.length)).setBody(new String(baos.toByteArray()));
conn.sendFrame(frame);
BytesMessage message = (BytesMessage) consumer.receive(10000);
Assert.assertNotNull(message);
assertEquals(data.length, message.getBodyLength());
assertEquals(data[0], message.readByte());
assertEquals(data[1], message.readByte());
assertEquals(data[2], message.readByte());
assertEquals(data[3], message.readByte());
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class StompV12Test method testSubscribeWithMessageSentWithProperties.
@Test
public void testSubscribeWithMessageSentWithProperties() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, "sub1", Stomp.Headers.Subscribe.AckModeValues.AUTO);
MessageProducer producer = session.createProducer(queue);
BytesMessage message = session.createBytesMessage();
message.setStringProperty("S", "value");
message.setBooleanProperty("n", false);
message.setByteProperty("byte", (byte) 9);
message.setDoubleProperty("d", 2.0);
message.setFloatProperty("f", (float) 6.0);
message.setIntProperty("i", 10);
message.setLongProperty("l", 121);
message.setShortProperty("s", (short) 12);
message.writeBytes("Hello World".getBytes(StandardCharsets.UTF_8));
producer.send(message);
ClientStompFrame frame = conn.receiveFrame();
Assert.assertNotNull(frame);
Assert.assertTrue(frame.getHeader("S") != null);
Assert.assertTrue(frame.getHeader("n") != null);
Assert.assertTrue(frame.getHeader("byte") != null);
Assert.assertTrue(frame.getHeader("d") != null);
Assert.assertTrue(frame.getHeader("f") != null);
Assert.assertTrue(frame.getHeader("i") != null);
Assert.assertTrue(frame.getHeader("l") != null);
Assert.assertTrue(frame.getHeader("s") != null);
Assert.assertEquals("Hello World", frame.getBody());
conn.disconnect();
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class BytesMessageTest method prepareMessage.
// Protected -----------------------------------------------------
@Override
protected void prepareMessage(final Message m) throws JMSException {
super.prepareMessage(m);
BytesMessage bm = (BytesMessage) m;
bm.writeBoolean(true);
bm.writeByte((byte) 3);
bm.writeBytes(new byte[] { (byte) 4, (byte) 5, (byte) 6 });
bm.writeChar((char) 7);
bm.writeDouble(8.0);
bm.writeFloat(9.0f);
bm.writeInt(10);
bm.writeLong(11L);
bm.writeShort((short) 12);
bm.writeUTF("this is an UTF String");
bm.reset();
}
Aggregations