use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class XmlDataImporter method processMessageBody.
private File processMessageBody(final ICoreMessage message) throws XMLStreamException, IOException {
File tempFileName = null;
boolean isLarge = false;
for (int i = 0; i < reader.getAttributeCount(); i++) {
String attributeName = reader.getAttributeLocalName(i);
if (XmlDataConstants.MESSAGE_IS_LARGE.equals(attributeName)) {
isLarge = Boolean.parseBoolean(reader.getAttributeValue(i));
}
}
reader.next();
if (logger.isDebugEnabled()) {
logger.debug("XMLStreamReader impl: " + reader);
}
if (isLarge) {
tempFileName = File.createTempFile("largeMessage", ".tmp");
if (logger.isDebugEnabled()) {
logger.debug("Creating temp file " + tempFileName + " for large message.");
}
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tempFileName))) {
getMessageBodyBytes(new MessageBodyBytesProcessor() {
@Override
public void processBodyBytes(byte[] bytes) throws IOException {
out.write(bytes);
}
});
}
FileInputStream fileInputStream = new FileInputStream(tempFileName);
BufferedInputStream bufferedInput = new BufferedInputStream(fileInputStream);
((ClientMessage) message).setBodyInputStream(bufferedInput);
} else {
getMessageBodyBytes(new MessageBodyBytesProcessor() {
@Override
public void processBodyBytes(byte[] bytes) throws IOException {
message.getBodyBuffer().writeBytes(bytes);
}
});
}
return tempFileName;
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class PostMessage method createActiveMQMessage.
protected ClientMessage createActiveMQMessage(HttpHeaders headers, byte[] body, boolean durable, Long ttl, Long expiration, Integer priority, ClientSession session) throws Exception {
ClientMessage message = session.createMessage(Message.BYTES_TYPE, durable);
// HORNETQ-962
UUID uid = UUIDGenerator.getInstance().generateUUID();
message.setUserID(uid);
if (expiration != null) {
message.setExpiration(expiration.longValue());
} else if (ttl != null) {
message.setExpiration(System.currentTimeMillis() + ttl.longValue());
} else if (producerTimeToLive > 0) {
message.setExpiration(System.currentTimeMillis() + producerTimeToLive);
}
if (priority != null) {
byte p = priority.byteValue();
if (p >= 0 && p <= 9) {
message.setPriority(p);
}
}
HttpMessageHelper.writeHttpMessage(headers, body, message);
return message;
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class PostMessage method publish.
public void publish(HttpHeaders headers, byte[] body, String dup, boolean durable, Long ttl, Long expiration, Integer priority) throws Exception {
Pooled pooled = getPooled();
try {
ClientProducer producer = pooled.producer;
ClientMessage message = createActiveMQMessage(headers, body, durable, ttl, expiration, priority, pooled.session);
message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID.toString(), dup);
producer.send(message);
ActiveMQRestLogger.LOGGER.debug("Sent message: " + message);
pool.add(pooled);
} catch (Exception ex) {
try {
pooled.session.close();
} catch (ActiveMQException e) {
}
addPooled();
throw ex;
}
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class QueueConsumer method pollWithIndex.
protected Response pollWithIndex(long wait, UriInfo info, String basePath, long index) {
try {
ClientMessage message = receive(wait);
if (message == null) {
Response.ResponseBuilder builder = Response.status(503).entity("Timed out waiting for message receive.").type("text/plain");
setPollTimeoutLinks(info, basePath, builder, Long.toString(index));
return builder.build();
}
previousIndex = index;
lastConsumed = ConsumedMessage.createConsumedMessage(message, this.getJmsOptions());
String token = Long.toString(lastConsumed.getMessageID());
Response response = getMessageResponse(lastConsumed, info, basePath, token).build();
if (autoAck)
message.acknowledge();
return response;
} catch (Exception e) {
Response errorResponse = Response.serverError().entity(e.getMessage()).status(Response.Status.INTERNAL_SERVER_ERROR).build();
return errorResponse;
}
}
use of org.apache.activemq.artemis.api.core.client.ClientMessage in project activemq-artemis by apache.
the class QueueConsumer method receiveFromConsumer.
protected ClientMessage receiveFromConsumer(long timeoutSecs) throws Exception {
ClientMessage m = null;
if (timeoutSecs <= 0) {
m = consumer.receive(1);
} else {
m = consumer.receive(timeoutSecs * 1000);
}
ActiveMQRestLogger.LOGGER.debug("Returning message " + m + " from consumer: " + consumer);
return m;
}
Aggregations