use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class DummyMessageQuery method execute.
@Override
public void execute(ActiveMQDestination destination, MessageListener listener) throws Exception {
LOG.info("Initial query is creating: " + MESSAGE_COUNT + " messages");
for (int i = 0; i < MESSAGE_COUNT; i++) {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText("Initial message: " + i + " loaded from query");
listener.onMessage(message);
}
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class SelectorTest method testXPathSelectors.
public void testXPathSelectors() throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setJMSType("xml");
message.setText("<root><a key='first' num='1'/><b key='second' num='2'>b</b></root>");
assertSelector(message, "XPATH 'root/a'", true);
assertSelector(message, "XPATH '//root/b'", true);
assertSelector(message, "XPATH 'root/c'", false);
assertSelector(message, "XPATH '//root/b/text()=\"b\"'", true);
assertSelector(message, "XPATH '//root/b=\"b\"'", true);
assertSelector(message, "XPATH '//root/b=\"c\"'", false);
assertSelector(message, "XPATH '//root/b!=\"c\"'", true);
assertSelector(message, "XPATH '//root/*[@key=''second'']'", true);
assertSelector(message, "XPATH '//root/*[@key=''third'']'", false);
assertSelector(message, "XPATH '//root/a[@key=''first'']'", true);
assertSelector(message, "XPATH '//root/a[@num=1]'", true);
assertSelector(message, "XPATH '//root/a[@key=''second'']'", false);
assertSelector(message, "XPATH '/root/*[@key=''first'' or @key=''third'']'", true);
assertSelector(message, "XPATH '//root/*[@key=''third'' or @key=''forth'']'", false);
assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''second'']'", true);
assertSelector(message, "XPATH '/root/b=''b'' and /root/b[@key=''first'']'", false);
assertSelector(message, "XPATH 'not(//root/a)'", false);
assertSelector(message, "XPATH 'not(//root/c)'", true);
assertSelector(message, "XPATH '//root/a[not(@key=''first'')]'", false);
assertSelector(message, "XPATH '//root/a[not(not(@key=''first''))]'", true);
assertSelector(message, "XPATH 'string(//root/b)'", true);
assertSelector(message, "XPATH 'string(//root/a)'", false);
assertSelector(message, "XPATH 'sum(//@num) < 10'", true);
assertSelector(message, "XPATH 'sum(//@num) > 10'", false);
assertSelector(message, "XPATH '//root/a[@num > 1]'", false);
assertSelector(message, "XPATH '//root/b[@num > 1]'", true);
}
use of org.apache.activemq.command.ActiveMQTextMessage in project webcert by sklintyg.
the class NotificationServiceImplTest method createTextMessage.
private TextMessage createTextMessage(String s) throws JMSException {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(s);
return message;
}
use of org.apache.activemq.command.ActiveMQTextMessage in project wildfly-camel by wildfly-extras.
the class ActiveMQIntegrationTest method testCustomMessageConverter.
@Test
public void testCustomMessageConverter() throws Exception {
MessageConverter converter = new MessageConverter() {
@Override
public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
return null;
}
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
TextMessage originalMessage = (TextMessage) message;
TextMessage modifiedMessage = new ActiveMQTextMessage();
modifiedMessage.setText(originalMessage.getText() + " Modified");
return modifiedMessage;
}
};
context.bind("messageConverter", converter);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
}
});
PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
pollingConsumer.start();
camelctx.start();
try {
ConnectionFactory connectionFactory = lookupConnectionFactory();
Connection con = connectionFactory.createConnection();
try {
sendMessage(con, "Kermit");
String result = pollingConsumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit Modified", result);
} finally {
con.close();
}
} finally {
camelctx.stop();
context.unbind("messageConverter");
}
}
use of org.apache.activemq.command.ActiveMQTextMessage in project wildfly-camel by wildfly-extras.
the class JMSIntegrationTest method testCustomMessageConverter.
@Test
public void testCustomMessageConverter() throws Exception {
MessageConverter converter = new MessageConverter() {
@Override
public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
return null;
}
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
TextMessage originalMessage = (TextMessage) message;
TextMessage modifiedMessage = new ActiveMQTextMessage();
modifiedMessage.setText(originalMessage.getText() + " Modified");
return modifiedMessage;
}
};
initialctx.bind("messageConverter", converter);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("jms:queue:%s?connectionFactory=ConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).to("seda:end");
}
});
camelctx.start();
PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
consumer.start();
try {
// Send a message to the queue
ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
Connection connection = cfactory.createConnection();
try {
sendMessage(connection, QUEUE_JNDI_NAME, "Kermit");
String result = consumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit Modified", result);
} finally {
connection.close();
}
} finally {
camelctx.stop();
initialctx.unbind("messageConverter");
}
}
Aggregations