use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.
the class TracingMessageListenerTest method starts_new_trace_if_none_exists_noConsumer.
@Test
public void starts_new_trace_if_none_exists_noConsumer() {
tracingMessageListener = new TracingMessageListener(delegate, jmsTracing, false);
ActiveMQTextMessage message = new ActiveMQTextMessage();
onMessageConsumed(message);
testSpanHandler.takeLocalSpan();
}
use of org.apache.activemq.command.ActiveMQTextMessage in project brave by openzipkin.
the class TracingMessageListenerTest method reports_span_if_consume_fails.
@Test
public void reports_span_if_consume_fails() {
tracingMessageListener = new TracingMessageListener(delegate, jmsTracing, false);
ActiveMQTextMessage message = new ActiveMQTextMessage();
RuntimeException error = new RuntimeException("Test exception");
onMessageConsumeFailed(message, error);
assertThat(testSpanHandler.takeLocalSpan().error()).isEqualTo(error);
}
use of org.apache.activemq.command.ActiveMQTextMessage in project vcell by virtualcell.
the class ClientTopicMessageCollector method onTopicMessage.
/**
* Insert the method's description here.
* Creation date: (10/23/2001 3:58:52 PM)
* @param message javax.jms.Message
* @throws VCMessagingException
*/
public void onTopicMessage(VCMessage message, VCMessageSession session) {
if (message == null) {
return;
}
try {
// Check if it's a broadcast message
if (message instanceof VCMessageJms) {
VCMessageJms vcMessageJms = (VCMessageJms) message;
javax.jms.Message myMessage = vcMessageJms.getJmsMessage();
if (myMessage instanceof ActiveMQTextMessage) {
ActiveMQTextMessage myAMQ = (ActiveMQTextMessage) myMessage;
if (myAMQ.getType().equalsIgnoreCase(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData(myAMQ.getText()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, null));
return;
}
}
}
if (message.getObjectContent() == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: unimplemented message class " + message.show());
}
setTimeSinceLastMessage(System.currentTimeMillis());
String msgType = message.getStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY);
if (msgType == null) {
throw new Exception(this.getClass().getName() + ".onTopicMessage: message type NULL for message " + message);
}
if (msgType.equals(MessageConstants.MESSAGE_TYPE_SIMSTATUS_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
StatusMessage statusMessage = new StatusMessage(message);
String userName = VCMessagingConstants.USERNAME_PROPERTY_VALUE_ALL;
if (message.propertyExists(VCMessagingConstants.USERNAME_PROPERTY)) {
userName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
}
SimulationJobStatus newJobStatus = statusMessage.getJobStatus();
if (newJobStatus == null) {
return;
}
VCSimulationIdentifier vcSimID = newJobStatus.getVCSimulationIdentifier();
Double progress = statusMessage.getProgress();
Double timePoint = statusMessage.getTimePoint();
fireSimulationJobStatusEvent(new SimulationJobStatusEvent(this, vcSimID.getID(), newJobStatus, progress, timePoint, messageUserName));
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_EXPORT_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
ExportEvent event = (ExportEvent) message.getObjectContent();
fireExportEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_DATA_EVENT_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
DataJobEvent event = (DataJobEvent) message.getObjectContent();
fireMessageEvent(event);
} else if (msgType.equals(MessageConstants.MESSAGE_TYPE_BROADCASTMESSAGE_VALUE)) {
String messageUserName = message.getStringProperty(VCMessagingConstants.USERNAME_PROPERTY);
fireMessageEvent(new VCellMessageEvent(this, System.currentTimeMillis() + "", new MessageData((BigString) message.getObjectContent()), VCellMessageEvent.VCELL_MESSAGEEVENT_TYPE_BROADCAST, messageUserName));
} else {
throw new Exception(this.getClass().getName() + ".onControlTopicMessage: Unimplemented message " + message.show());
}
} catch (Exception e) {
e.printStackTrace();
lg.error(e.getMessage(), e);
}
}
use of org.apache.activemq.command.ActiveMQTextMessage in project nifi by apache.
the class TestJmsConsumer method testMap2FlowFileTextMessage.
@Test
public void testMap2FlowFileTextMessage() throws Exception {
TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
TextMessage textMessage = new ActiveMQTextMessage();
String payload = "Hello world!";
textMessage.setText(payload);
ProcessContext context = runner.getProcessContext();
ProcessSession session = runner.getProcessSessionFactory().createSession();
ProcessorInitializationContext pic = new MockProcessorInitializationContext(runner.getProcessor(), (MockProcessContext) runner.getProcessContext());
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger());
assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize());
final byte[] buffer = new byte[payload.length()];
runner.clearTransferState();
session.read(summary.getLastFlowFile(), new InputStreamCallback() {
@Override
public void process(InputStream in) throws IOException {
StreamUtils.fillBuffer(in, buffer, false);
}
});
String contentString = new String(buffer, "UTF-8");
assertEquals("", payload, contentString);
}
use of org.apache.activemq.command.ActiveMQTextMessage in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testConsumerCloseTransactionalSendReceive.
public void testConsumerCloseTransactionalSendReceive() 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);
producer.close();
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);
consumer.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);
}
Aggregations