use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class BridgeImpl method beforeForward.
/* Hook for processing message before forwarding */
protected Message beforeForward(final Message message, final SimpleString forwardingAddress) {
if (useDuplicateDetection) {
// We keep our own DuplicateID for the Bridge, so bouncing back and forth will work fine
byte[] bytes = getDuplicateBytes(nodeUUID, message.getMessageID());
message.putExtraBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, bytes);
}
if (forwardingAddress != null) {
// for AMQP messages this modification will be transient
message.setAddress(forwardingAddress);
}
if (transformer != null) {
final Message transformedMessage = transformer.transform(message);
if (transformedMessage != message) {
if (logger.isDebugEnabled()) {
logger.debug("The transformer " + transformer + " made a copy of the message " + message + " as transformedMessage");
}
}
return EmbedMessageUtil.embedAsCoreMessage(transformedMessage);
} else {
return EmbedMessageUtil.embedAsCoreMessage(message);
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class BridgeImpl method handle.
@Override
public HandleStatus handle(final MessageReference ref) throws Exception {
if (filter != null && !filter.match(ref.getMessage())) {
return HandleStatus.NO_MATCH;
}
synchronized (this) {
if (!active || !session.isWritable(this)) {
if (logger.isDebugEnabled()) {
logger.debug(this + "::Ignoring reference on bridge as it is set to inactive ref=" + ref);
}
return HandleStatus.BUSY;
}
if (blockedOnFlowControl) {
return HandleStatus.BUSY;
}
if (deliveringLargeMessage) {
return HandleStatus.BUSY;
}
if (logger.isTraceEnabled()) {
logger.trace("Bridge " + this + " is handling reference=" + ref);
}
ref.handled();
synchronized (refs) {
refs.put(ref.getMessage().getMessageID(), ref);
}
final SimpleString dest;
if (forwardingAddress != null) {
dest = forwardingAddress;
} else {
// Preserve the original address
dest = ref.getMessage().getAddressSimpleString();
}
final Message message = beforeForward(ref.getMessage(), dest);
pendingAcks.countUp();
try {
if (message.isLargeMessage()) {
deliveringLargeMessage = true;
deliverLargeMessage(dest, ref, (LargeServerMessage) message);
return HandleStatus.HANDLED;
} else {
return deliverStandardMessage(dest, ref, message);
}
} catch (Exception e) {
// If an exception happened, we must count down immediately
pendingAcks.countDown();
throw e;
}
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class MQTTRetainMessageManager method addRetainedMessagesToQueue.
// SEND to Queue.
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception {
// The address filter that matches all retained message queues.
String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration());
BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress));
// Iterate over all matching retain queues and add the queue
Transaction tx = session.getServerSession().newTransaction();
try {
synchronized (queue) {
for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) {
Queue retainedQueue = session.getServer().locateQueue(retainedQueueName);
try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) {
if (i.hasNext()) {
Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID());
sendToQueue(message, queue, tx);
}
}
}
}
} catch (Throwable t) {
tx.rollback();
throw t;
}
tx.commit();
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class XmlDataImporter method processMessage.
private void processMessage() throws Exception {
Byte type = 0;
Byte priority = 0;
Long expiration = 0L;
Long timestamp = 0L;
Long id = 0L;
org.apache.activemq.artemis.utils.UUID userId = null;
ArrayList<String> queues = new ArrayList<>();
// get message's attributes
for (int i = 0; i < reader.getAttributeCount(); i++) {
String attributeName = reader.getAttributeLocalName(i);
switch(attributeName) {
case XmlDataConstants.MESSAGE_TYPE:
type = getMessageType(reader.getAttributeValue(i));
break;
case XmlDataConstants.MESSAGE_PRIORITY:
priority = Byte.parseByte(reader.getAttributeValue(i));
break;
case XmlDataConstants.MESSAGE_EXPIRATION:
expiration = Long.parseLong(reader.getAttributeValue(i));
break;
case XmlDataConstants.MESSAGE_TIMESTAMP:
timestamp = Long.parseLong(reader.getAttributeValue(i));
break;
case XmlDataConstants.MESSAGE_USER_ID:
userId = UUIDGenerator.getInstance().generateUUID();
break;
case XmlDataConstants.MESSAGE_ID:
id = Long.parseLong(reader.getAttributeValue(i));
break;
}
}
Message message = session.createMessage(type, true, expiration, timestamp, priority);
message.setUserID(userId);
boolean endLoop = false;
File largeMessageTemporaryFile = null;
// loop through the XML and gather up all the message's data (i.e. body, properties, queues, etc.)
while (reader.hasNext()) {
int eventType = reader.getEventType();
switch(eventType) {
case XMLStreamConstants.START_ELEMENT:
if (XmlDataConstants.MESSAGE_BODY.equals(reader.getLocalName())) {
largeMessageTemporaryFile = processMessageBody(message.toCore());
} else if (XmlDataConstants.PROPERTIES_CHILD.equals(reader.getLocalName())) {
processMessageProperties(message);
} else if (XmlDataConstants.QUEUES_CHILD.equals(reader.getLocalName())) {
processMessageQueues(queues);
}
break;
case XMLStreamConstants.END_ELEMENT:
if (XmlDataConstants.MESSAGES_CHILD.equals(reader.getLocalName())) {
endLoop = true;
}
break;
}
if (endLoop) {
break;
}
reader.next();
}
if (sort) {
messages.add(new MessageTemp(id, queues, message, largeMessageTemporaryFile));
} else {
sendMessage(queues, message, largeMessageTemporaryFile);
}
}
use of org.apache.activemq.artemis.api.core.Message in project activemq-artemis by apache.
the class InterruptedLargeMessageTest method testInterruptLargeMessageSend.
@Test
public void testInterruptLargeMessageSend() throws Exception {
ClientSession session = null;
LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
ActiveMQServer server = createServer(true, isNetty());
server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
server.start();
locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false);
ClientSessionFactory sf = createSessionFactory(locator);
session = sf.createSession(false, true, true);
session.createQueue(ADDRESS, ADDRESS, true);
ClientProducer producer = session.createProducer(ADDRESS);
Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
clientFile.setExpiration(System.currentTimeMillis());
producer.send(clientFile);
Thread.sleep(500);
//
// for (ServerSession srvSession : server.getSessions()) {
// ((ServerSessionImpl) srvSession).clearLargeMessage();
// }
server.fail(false);
ActiveMQTestBase.forceGC();
server.start();
server.stop();
validateNoFilesOnLargeDir();
}
Aggregations