use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class ActiveMQMessageHandler method onMessage.
@Override
public void onMessage(final ClientMessage message) {
if (logger.isTraceEnabled()) {
logger.trace("onMessage(" + message + ")");
}
ActiveMQMessage msg = ActiveMQMessage.createMessage(message, session, options);
boolean beforeDelivery = false;
try {
if (activation.getActivationSpec().getTransactionTimeout() > 0 && tm != null) {
tm.setTransactionTimeout(activation.getActivationSpec().getTransactionTimeout());
}
if (logger.isTraceEnabled()) {
logger.trace("HornetQMessageHandler::calling beforeDelivery on message " + message);
}
endpoint.beforeDelivery(ActiveMQActivation.ONMESSAGE);
beforeDelivery = true;
msg.doBeforeReceive();
if (transacted) {
message.individualAcknowledge();
}
((MessageListener) endpoint).onMessage(msg);
if (!transacted) {
message.individualAcknowledge();
}
if (logger.isTraceEnabled()) {
logger.trace("HornetQMessageHandler::calling afterDelivery on message " + message);
}
try {
endpoint.afterDelivery();
} catch (ResourceException e) {
ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e);
// If we get here, The TX was already rolled back
// However we must do some stuff now to make sure the client message buffer is cleared
// so we mark this as rollbackonly
session.markRollbackOnly();
return;
}
if (useLocalTx) {
session.commit();
}
if (logger.isTraceEnabled()) {
logger.trace("finished onMessage on " + message);
}
} catch (Throwable e) {
ActiveMQRALogger.LOGGER.errorDeliveringMessage(e);
// we need to call before/afterDelivery as a pair
if (beforeDelivery) {
if (useXA && tm != null) {
// this is to avoid a scenario where afterDelivery would kick in
try {
Transaction tx = tm.getTransaction();
if (tx != null) {
tx.setRollbackOnly();
}
} catch (Exception e1) {
ActiveMQRALogger.LOGGER.unableToClearTheTransaction(e1);
}
}
MessageEndpoint endToUse = endpoint;
try {
// to avoid a NPE that would happen while the RA is in tearDown
if (endToUse != null) {
endToUse.afterDelivery();
}
} catch (ResourceException e1) {
ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e1);
}
}
if (useLocalTx || !activation.isDeliveryTransacted()) {
try {
session.rollback(true);
} catch (ActiveMQException e1) {
ActiveMQRALogger.LOGGER.unableToRollbackTX();
}
}
// This is to make sure we will issue a rollback after failures
// so that would cleanup consumer buffers among other things
session.markRollbackOnly();
} finally {
try {
session.resetIfNeeded();
} catch (ActiveMQException e) {
ActiveMQRALogger.LOGGER.unableToResetSession(activation.toString(), e);
activation.startReconnectThread("Reset MessageHandler after Failure Thread");
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class TopicClusterTest method checkInternalProperty.
// check that the internal property is in the core
// but didn't exposed to jms
private void checkInternalProperty(Message... msgs) throws Exception {
boolean checked = false;
for (Message m : msgs) {
ActiveMQMessage hqMessage = (ActiveMQMessage) m;
ClientMessage coreMessage = hqMessage.getCoreMessage();
Set<SimpleString> coreProps = coreMessage.getPropertyNames();
System.out.println("core props: " + coreProps);
boolean exist = false;
for (SimpleString prop : coreProps) {
if (prop.startsWith(org.apache.activemq.artemis.api.core.Message.HDR_ROUTE_TO_IDS)) {
exist = true;
break;
}
}
if (exist) {
Enumeration enumProps = m.getPropertyNames();
while (enumProps.hasMoreElements()) {
String propName = (String) enumProps.nextElement();
assertFalse("Shouldn't be in jms property: " + propName, propName.startsWith(org.apache.activemq.artemis.api.core.Message.HDR_ROUTE_TO_IDS.toString()));
}
checked = true;
}
}
assertTrue(checked);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class JMSBridgeTest method messageIDInHeader.
private void messageIDInHeader(final boolean on) throws Exception {
JMSBridgeImpl bridge = null;
Connection connSource = null;
Connection connTarget = null;
try {
final int NUM_MESSAGES = 10;
bridge = new JMSBridgeImpl(cff0, cff1, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 5000, 10, QualityOfServiceMode.AT_MOST_ONCE, 1, -1, null, null, on);
bridge.start();
connSource = cf0.createConnection();
connTarget = cf1.createConnection();
JMSBridgeTest.log.trace("Sending " + NUM_MESSAGES + " messages");
List<String> ids1 = new ArrayList<>();
Session sessSource = connSource.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sessSource.createProducer(sourceQueue);
for (int i = 0; i < NUM_MESSAGES; i++) {
TextMessage tm = sessSource.createTextMessage("message" + i);
// We add some properties to make sure they get passed through ok
tm.setStringProperty("wib", "uhuh");
tm.setBooleanProperty("cheese", true);
tm.setIntProperty("Sausages", 23);
tm.setByteProperty("bacon", (byte) 12);
tm.setDoubleProperty("toast", 17261762.12121d);
tm.setFloatProperty("orange", 1212.1212f);
tm.setLongProperty("blurg", 817217827L);
tm.setShortProperty("stst", (short) 26363);
// Set some JMS headers too
// And also set a core props
((ActiveMQMessage) tm).getCoreMessage().putBytesProperty("bytes", new byte[] { 1, 2, 3 });
// We add some JMSX ones too
tm.setStringProperty("JMSXGroupID", "mygroup543");
prod.send(tm);
ids1.add(tm.getJMSMessageID());
}
JMSBridgeTest.log.trace("Sent the first messages");
Session sessTarget = connTarget.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = sessTarget.createConsumer(targetQueue);
connTarget.start();
List<TextMessage> msgs = new ArrayList<>();
for (int i = 0; i < NUM_MESSAGES; i++) {
TextMessage tm = (TextMessage) cons.receive(5000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
Assert.assertTrue(tm.getBooleanProperty("cheese"));
Assert.assertEquals(23, tm.getIntProperty("Sausages"));
assertEquals((byte) 12, tm.getByteProperty("bacon"));
assertEquals(17261762.12121d, tm.getDoubleProperty("toast"), 0.000000001);
assertEquals(1212.1212f, tm.getFloatProperty("orange"), 0.000001);
assertEquals(817217827L, tm.getLongProperty("blurg"));
assertEquals((short) 26363, tm.getShortProperty("stst"));
assertEqualsByteArrays(new byte[] { 1, 2, 3 }, ((ActiveMQMessage) tm).getCoreMessage().getBytesProperty("bytes"));
Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
if (on) {
String header = tm.getStringProperty(ActiveMQJMSConstants.AMQ_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
Assert.assertNotNull(header);
Assert.assertEquals(ids1.get(i), header);
msgs.add(tm);
}
}
if (on) {
// Now we send them again back to the source
Iterator<TextMessage> iter = msgs.iterator();
List<String> ids2 = new ArrayList<>();
while (iter.hasNext()) {
Message msg = iter.next();
prod.send(msg);
ids2.add(msg.getJMSMessageID());
}
for (int i = 0; i < NUM_MESSAGES; i++) {
TextMessage tm = (TextMessage) cons.receive(5000);
Assert.assertNotNull(tm);
Assert.assertEquals("message" + i, tm.getText());
Assert.assertEquals("uhuh", tm.getStringProperty("wib"));
Assert.assertTrue(tm.getBooleanProperty("cheese"));
Assert.assertEquals(23, tm.getIntProperty("Sausages"));
assertEquals((byte) 12, tm.getByteProperty("bacon"));
assertEquals(17261762.12121d, tm.getDoubleProperty("toast"), 0.000001);
assertEquals(1212.1212f, tm.getFloatProperty("orange"), 0.0000001);
assertEquals(817217827L, tm.getLongProperty("blurg"));
assertEquals((short) 26363, tm.getShortProperty("stst"));
assertEqualsByteArrays(new byte[] { 1, 2, 3 }, ((ActiveMQMessage) tm).getCoreMessage().getBytesProperty("bytes"));
Assert.assertEquals("mygroup543", tm.getStringProperty("JMSXGroupID"));
String header = tm.getStringProperty(ActiveMQJMSConstants.AMQ_MESSAGING_BRIDGE_MESSAGE_ID_LIST);
Assert.assertNotNull(header);
Assert.assertEquals(ids1.get(i) + "," + ids2.get(i), header);
}
}
} finally {
if (bridge != null) {
bridge.stop();
}
if (connSource != null) {
connSource.close();
}
if (connTarget != null) {
connTarget.close();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class MessageHeaderTest method testCopyOnJBossMessage.
@Test
public void testCopyOnJBossMessage() throws JMSException {
ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000);
ClientSession session = new FakeSession(clientMessage);
ActiveMQMessage jbossMessage = ActiveMQMessage.createMessage(clientMessage, session);
jbossMessage.clearProperties();
MessageHeaderTestBase.configureMessage(jbossMessage);
ActiveMQMessage copy = new ActiveMQMessage(jbossMessage, session);
MessageHeaderTestBase.ensureEquivalent(jbossMessage, copy);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQMessage in project activemq-artemis by apache.
the class MessageHeaderTest method testForeignJMSDestination.
@Test
public void testForeignJMSDestination() throws JMSException {
Message message = queueProducerSession.createMessage();
Destination foreignDestination = new ForeignDestination();
message.setJMSDestination(foreignDestination);
ProxyAssertSupport.assertSame(foreignDestination, message.getJMSDestination());
queueProducer.send(message);
ProxyAssertSupport.assertSame(queue1, message.getJMSDestination());
Message receivedMessage = queueConsumer.receive(2000);
MessageHeaderTestBase.ensureEquivalent(receivedMessage, (ActiveMQMessage) message);
}
Aggregations