use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class CompressedInteropTest method sendCompressedBytesMessageUsingOpenWire.
private void sendCompressedBytesMessageUsingOpenWire() throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(TEXT.getBytes());
producer.send(bytesMessage);
}
use of javax.jms.BytesMessage in project activemq-artemis by apache.
the class CompressedInteropTest method receiveBytesMessage.
private void receiveBytesMessage(boolean useCore) throws Exception {
BytesMessage bytesMessage = (BytesMessage) receiveMessage(useCore);
byte[] bytes = new byte[TEXT.getBytes(StandardCharsets.UTF_8).length];
bytesMessage.readBytes(bytes);
assertTrue(bytesMessage.readBytes(new byte[255]) == -1);
String rcvString = new String(bytes, StandardCharsets.UTF_8);
assertEquals(TEXT, rcvString);
}
use of javax.jms.BytesMessage in project meteo by pierre.
the class TopicListener method onMessage.
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
TextMessage txtMsg = (TextMessage) message;
String txt = null;
try {
txt = txtMsg.getText();
log.debug("Received a message, yay!\n" + txt);
Map event = mapper.readValue(txt, Map.class);
esperSink.getEPRuntime().sendEvent(event, esperTopicKey);
} catch (JMSException ex) {
log.warn("Got an error from the message queue", ex);
} catch (ClassCastException ex) {
log.info("Received message that I couldn't parse: " + txt, ex);
} catch (JsonMappingException ex) {
log.info("Received message that I couldn't parse: " + txt, ex);
} catch (JsonParseException ex) {
log.info("Received message that I couldn't parse: " + txt, ex);
} catch (IOException ex) {
log.warn("Got an error from the message queue", ex);
}
} else if (message instanceof BytesMessage) {
final BytesMessage byteMessage = (BytesMessage) message;
long llen;
try {
llen = byteMessage.getBodyLength();
} catch (JMSException e) {
log.warn("Unable to get message length", e);
return;
}
if (llen > Integer.MAX_VALUE) {
// should never occur but...
log.error("Ridiculously huge message payload, above 32-bit length");
} else {
final int len = (int) llen;
final byte[] data = new byte[len];
final int readLen;
try {
readLen = byteMessage.readBytes(data);
} catch (JMSException e) {
log.warn("Unable to get message bytes", e);
return;
}
if (readLen < len) {
log.error("Failed to read byte message contents; read {}, was trying to read {}", readLen, data.length);
} else {
final Map event;
try {
event = mapper.readValue(data, Map.class);
esperSink.getEPRuntime().sendEvent(event, esperTopicKey);
} catch (IOException e) {
log.error("Failed to convert message to Esper Event", readLen, data.length);
}
}
}
} else {
log.error("Unexpected message type '{}' from AMQ broker: must skip", message.getClass().getName());
}
}
use of javax.jms.BytesMessage in project jmeter by apache.
the class JMSSampler method extractContent.
@SuppressWarnings("JdkObsolete")
private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg) {
if (msg != null) {
try {
if (msg instanceof TextMessage) {
buffer.append(((TextMessage) msg).getText());
} else if (msg instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) msg;
if (objectMessage.getObject() != null) {
buffer.append(objectMessage.getObject().getClass());
} else {
buffer.append("object is null");
}
} else if (msg instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) msg;
buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
} else if (msg instanceof MapMessage) {
MapMessage mapm = (MapMessage) msg;
// MapNames are Strings
@SuppressWarnings("unchecked") Enumeration<String> enumb = mapm.getMapNames();
while (enumb.hasMoreElements()) {
String name = enumb.nextElement();
Object obj = mapm.getObject(name);
buffer.append(name);
buffer.append(",");
buffer.append(obj.getClass().getCanonicalName());
buffer.append(",");
buffer.append(obj);
buffer.append("\n");
}
}
Utils.messageProperties(propBuffer, msg);
} catch (JMSException e) {
buffer.append("Error extracting content from message:" + e.getMessage());
LOGGER.error("Error extracting content from message", e);
}
}
}
use of javax.jms.BytesMessage in project jmeter by apache.
the class SubscriberSampler method extractContent.
@SuppressWarnings("JdkObsolete")
private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) {
if (msg != null) {
try {
if (msg instanceof TextMessage) {
buffer.append(((TextMessage) msg).getText());
} else if (msg instanceof ObjectMessage) {
ObjectMessage objectMessage = (ObjectMessage) msg;
if (objectMessage.getObject() != null) {
buffer.append(objectMessage.getObject().getClass());
} else {
buffer.append("object is null");
}
} else if (msg instanceof BytesMessage) {
BytesMessage bytesMessage = (BytesMessage) msg;
buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
} else if (msg instanceof MapMessage) {
MapMessage mapm = (MapMessage) msg;
// MapNames are Strings
@SuppressWarnings("unchecked") Enumeration<String> enumb = mapm.getMapNames();
while (enumb.hasMoreElements()) {
String name = enumb.nextElement();
Object obj = mapm.getObject(name);
buffer.append(name);
buffer.append(",");
buffer.append(obj.getClass().getCanonicalName());
buffer.append(",");
buffer.append(obj);
buffer.append("\n");
}
}
Utils.messageProperties(propBuffer, msg);
if (!isLast && !StringUtils.isEmpty(separator)) {
propBuffer.append(separator);
buffer.append(separator);
}
} catch (JMSException e) {
log.error(e.getMessage());
}
}
}
Aggregations