Search in sources :

Example 1 with InvalidStateException

use of com.swiftmq.amqp.v100.client.InvalidStateException in project swiftmq-client by iitsoftware.

the class AMQPMessage method accept.

/**
 * Accepts delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
 *
 * @throws InvalidStateException If the state is invalid to perform this operation
 */
public void accept() throws InvalidStateException {
    if (consumer == null)
        throw new InvalidStateException("Message not associated with a consumer");
    if (settled && txnIdIF == null)
        throw new InvalidStateException("Accept not required; message has already been settled");
    DeliveryStateIF deliveryStateIF = null;
    if (txnIdIF == null)
        deliveryStateIF = new Accepted();
    else {
        TransactionalState transactionalState = new TransactionalState();
        transactionalState.setTxnId(txnIdIF);
        transactionalState.setOutcome(new Accepted());
        deliveryStateIF = transactionalState;
    }
    consumer.sendDisposition(this, deliveryStateIF);
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) InvalidStateException(com.swiftmq.amqp.v100.client.InvalidStateException) Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Example 2 with InvalidStateException

use of com.swiftmq.amqp.v100.client.InvalidStateException in project swiftmq-client by iitsoftware.

the class AMQPMessage method reject.

/**
 * <p>Rejects delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
 * </p>
 * <p>
 * This operation causes the delivery count to be incremented and the message to be redelivered to this or other
 * competing consumers.
 * </p>
 *
 * @throws InvalidStateException If the state is invalid to perform this operation
 */
public void reject() throws InvalidStateException {
    if (consumer == null)
        throw new InvalidStateException("Message not associated with a consumer");
    if (settled && txnIdIF == null)
        throw new InvalidStateException("Reject not possible; message has already been settled");
    DeliveryStateIF deliveryStateIF = null;
    if (txnIdIF == null)
        deliveryStateIF = new Rejected();
    else {
        TransactionalState transactionalState = new TransactionalState();
        transactionalState.setTxnId(txnIdIF);
        transactionalState.setOutcome(new Rejected());
        deliveryStateIF = transactionalState;
    }
    consumer.sendDisposition(this, deliveryStateIF);
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) InvalidStateException(com.swiftmq.amqp.v100.client.InvalidStateException) Rejected(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Aggregations

InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)1