use of org.apache.activemq.command.ProducerAck in project activemq-artemis by apache.
the class AMQSession method send.
public void send(final ProducerInfo producerInfo, final Message messageSend, final boolean sendProducerAck) throws Exception {
messageSend.setBrokerInTime(System.currentTimeMillis());
final ActiveMQDestination destination = messageSend.getDestination();
final ActiveMQDestination[] actualDestinations;
final int actualDestinationsCount;
if (destination.isComposite()) {
actualDestinations = destination.getCompositeDestinations();
messageSend.setOriginalDestination(destination);
actualDestinationsCount = actualDestinations.length;
} else {
actualDestinations = null;
actualDestinationsCount = 1;
}
final org.apache.activemq.artemis.api.core.Message originalCoreMsg = OpenWireMessageConverter.inbound(messageSend, protocolManagerWireFormat, coreMessageObjectPools);
assert clientId.toString().equals(this.connection.getState().getInfo().getClientId()) : "Session cached clientId must be the same of the connection";
originalCoreMsg.putStringProperty(MessageUtil.CONNECTION_ID_PROPERTY_NAME, clientId);
/* ActiveMQ failover transport will attempt to reconnect after connection failure. Any sent messages that did
* not receive acks will be resent. (ActiveMQ broker handles this by returning a last sequence id received to
* the client). To handle this in Artemis we use a duplicate ID cache. To do this we check to see if the
* message comes from failover connection. If so we add a DUPLICATE_ID to handle duplicates after a resend. */
if (connection.getContext().isFaultTolerant() && !messageSend.getProperties().containsKey(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID.toString())) {
originalCoreMsg.putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_DUPLICATE_DETECTION_ID, SimpleString.toSimpleString(messageSend.getMessageId().toString()));
}
final boolean shouldBlockProducer = producerInfo.getWindowSize() > 0 || messageSend.isResponseRequired();
final AtomicInteger count = actualDestinations != null ? new AtomicInteger(actualDestinationsCount) : null;
if (shouldBlockProducer) {
connection.getContext().setDontSendReponse(true);
}
for (int i = 0; i < actualDestinationsCount; i++) {
final ActiveMQDestination dest = actualDestinations != null ? actualDestinations[i] : destination;
final String physicalName = dest.getPhysicalName();
final SimpleString address = SimpleString.toSimpleString(physicalName, coreMessageObjectPools.getAddressStringSimpleStringPool());
// the last coreMsg could be directly the original one -> it avoid 1 copy if actualDestinations > 1 and ANY copy if actualDestinations == 1
final org.apache.activemq.artemis.api.core.Message coreMsg = (i == actualDestinationsCount - 1) ? originalCoreMsg : originalCoreMsg.copy();
coreMsg.setAddress(address);
if (dest.isQueue()) {
checkCachedExistingQueues(address, physicalName, dest.isTemporary());
coreMsg.setRoutingType(RoutingType.ANYCAST);
} else {
coreMsg.setRoutingType(RoutingType.MULTICAST);
}
final PagingStore store = server.getPagingManager().getPageStore(address);
this.connection.disableTtl();
if (shouldBlockProducer) {
sendShouldBlockProducer(producerInfo, messageSend, sendProducerAck, store, dest, count, coreMsg, address);
} else {
// non-persistent messages goes here, by default we stop reading from
// transport
connection.getTransportConnection().setAutoRead(false);
if (!store.checkMemory(enableAutoReadAndTtl)) {
enableAutoReadAndTtl();
throw new ResourceAllocationException("Queue is full " + address);
}
getCoreSession().send(coreMsg, false, dest.isTemporary());
if (count == null || count.decrementAndGet() == 0) {
if (sendProducerAck) {
final ProducerAck ack = new ProducerAck(producerInfo.getProducerId(), messageSend.getSize());
connection.dispatchAsync(ack);
}
}
}
}
}
use of org.apache.activemq.command.ProducerAck in project activemq-artemis by apache.
the class ProducerAckTest method createObject.
@Override
public Object createObject() throws Exception {
ProducerAck info = new ProducerAck();
populateObject(info);
return info;
}
use of org.apache.activemq.command.ProducerAck in project activemq-artemis by apache.
the class ProducerAckTest method populateObject.
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
ProducerAck info = (ProducerAck) object;
info.setProducerId(createProducerId("ProducerId:1"));
info.setSize(1);
}
use of org.apache.activemq.command.ProducerAck in project activemq-artemis by apache.
the class ProducerAckTest method createObject.
@Override
public Object createObject() throws Exception {
ProducerAck info = new ProducerAck();
populateObject(info);
return info;
}
use of org.apache.activemq.command.ProducerAck in project activemq-artemis by apache.
the class ProducerAckTest method populateObject.
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
ProducerAck info = (ProducerAck) object;
info.setProducerId(createProducerId("ProducerId:1"));
info.setSize(1);
}
Aggregations