Search in sources :

Example 1 with ProducerAck

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);
                }
            }
        }
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ProducerAck(org.apache.activemq.command.ProducerAck) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ResourceAllocationException(javax.jms.ResourceAllocationException) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore)

Example 2 with ProducerAck

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;
}
Also used : ProducerAck(org.apache.activemq.command.ProducerAck)

Example 3 with ProducerAck

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);
}
Also used : ProducerAck(org.apache.activemq.command.ProducerAck)

Example 4 with ProducerAck

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;
}
Also used : ProducerAck(org.apache.activemq.command.ProducerAck)

Example 5 with ProducerAck

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);
}
Also used : ProducerAck(org.apache.activemq.command.ProducerAck)

Aggregations

ProducerAck (org.apache.activemq.command.ProducerAck)16 ResourceAllocationException (javax.jms.ResourceAllocationException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)1 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 Response (org.apache.activemq.command.Response)1