use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testSessionCloseTransactionalSendReceive.
public void testSessionCloseTransactionalSendReceive() throws Exception {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection) cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
session.close();
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session = connection1.createXASession();
MessageConsumer consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
session.close();
assertNotNull(receivedMessage);
assertEquals(getName(), receivedMessage.getText());
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session = connection1.createXASession();
consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
assertNull(consumer.receive(1000));
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testVanilaTransactionalProduceReceive.
public void testVanilaTransactionalProduceReceive() throws Exception {
XAConnection connection1 = null;
try {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
connection1 = (XAConnection) cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session.close();
session = connection1.createXASession();
MessageConsumer consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
assertNotNull(receivedMessage);
assertEquals(getName(), receivedMessage.getText());
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session.close();
} finally {
if (connection1 != null) {
try {
connection1.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class CompressionOverNetworkTest method testCompressedOverCompressedNetwork.
@Test
public void testCompressedOverCompressedNetwork() throws Exception {
ActiveMQConnection localAmqConnection = (ActiveMQConnection) localConnection;
localAmqConnection.setUseCompression(true);
MessageConsumer consumer1 = remoteSession.createConsumer(included);
MessageProducer producer = localSession.createProducer(included);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
waitForConsumerRegistration(localBroker, 1, included);
StringBuilder payload = new StringBuilder("test-");
for (int i = 0; i < 100; ++i) {
payload.append(UUID.randomUUID().toString());
}
Message test = localSession.createTextMessage(payload.toString());
producer.send(test);
Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS);
assertNotNull(msg);
ActiveMQTextMessage message = (ActiveMQTextMessage) msg;
assertTrue(message.isCompressed());
assertEquals(payload.toString(), message.getText());
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class BrokerNetworkWithStuckMessagesTest method createMessage.
protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
message.setDestination(destination);
message.setPersistent(false);
try {
message.setText("Test Message Payload.");
} catch (MessageNotWriteableException e) {
}
return message;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class NetworkLoadTest method testRequestReply.
public void testRequestReply() throws Exception {
// Send to the first broker
final int to = 0;
// consume from the last broker..
int from = brokers.length - 1;
LOG.info("Staring Final Consumer");
Connection fromConnection = createConnection(from);
fromConnection.start();
Session fromSession = fromConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = fromSession.createConsumer(new ActiveMQQueue("Q" + from));
final AtomicReference<ActiveMQTextMessage> lastMessageReceived = new AtomicReference<>();
final AtomicLong producedMessages = new AtomicLong();
final AtomicLong receivedMessages = new AtomicLong();
final AtomicBoolean done = new AtomicBoolean();
// Setup the consumer..
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
ActiveMQTextMessage m = (ActiveMQTextMessage) msg;
ActiveMQTextMessage last = lastMessageReceived.get();
if (last != null) {
// Some order checking...
if (last.getMessageId().getProducerSequenceId() > m.getMessageId().getProducerSequenceId()) {
System.out.println("Received an out of order message. Got " + m.getMessageId() + ", expected something after " + last.getMessageId());
}
}
lastMessageReceived.set(m);
receivedMessages.incrementAndGet();
}
});
LOG.info("Staring Initial Producer");
final Connection toConnection = createConnection(to);
Thread producer = new Thread("Producer") {
@Override
public void run() {
try {
toConnection.start();
Session toSession = toConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = toSession.createProducer(new ActiveMQQueue("Q" + to));
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setDisableMessageID(true);
for (int i = 0; !done.get(); i++) {
TextMessage msg = toSession.createTextMessage(createMessageText(i));
producer.send(msg);
producedMessages.incrementAndGet();
}
} catch (JMSException e) {
e.printStackTrace();
}
}
private String createMessageText(int index) {
StringBuffer buffer = new StringBuffer(MESSAGE_SIZE);
buffer.append(index + " on " + new Date() + " ...");
if (buffer.length() > MESSAGE_SIZE) {
return buffer.substring(0, MESSAGE_SIZE);
}
for (int i = buffer.length(); i < MESSAGE_SIZE; i++) {
buffer.append(' ');
}
return buffer.toString();
}
};
producer.start();
// Give the forwarding clients a chance to get going and fill the down
// stream broker queues..
Thread.sleep(BROKER_COUNT * 200);
for (int i = 0; i < SAMPLES; i++) {
long start = System.currentTimeMillis();
producedMessages.set(0);
receivedMessages.set(0);
for (int j = 0; j < forwardingClients.length; j++) {
forwardingClients[j].forwardCounter.set(0);
}
Thread.sleep(SAMPLE_DURATION);
long end = System.currentTimeMillis();
long r = receivedMessages.get();
long p = producedMessages.get();
LOG.info("published: " + p + " msgs at " + (p * 1000f / (end - start)) + " msgs/sec, " + "consumed: " + r + " msgs at " + (r * 1000f / (end - start)) + " msgs/sec");
StringBuffer fwdingmsg = new StringBuffer(500);
fwdingmsg.append(" forwarding counters: ");
for (int j = 0; j < forwardingClients.length; j++) {
if (j != 0) {
fwdingmsg.append(", ");
}
fwdingmsg.append(forwardingClients[j].forwardCounter.get());
}
LOG.info(fwdingmsg.toString());
// The test is just checking to make sure thaat the producer and consumer does not hang
// due to the network hops take to route the message form the producer to the consumer.
assertTrue("Received some messages since last sample", r > 0);
assertTrue("Produced some messages since last sample", p > 0);
}
LOG.info("Sample done.");
done.set(true);
// Wait for the producer to finish.
producer.join(1000 * 5);
toConnection.close();
fromConnection.close();
}
Aggregations