2014-12-11 07:17:29 -05:00
|
|
|
# Extra Acknowledge Modes
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
JMS specifies 3 acknowledgement modes:
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
- `AUTO_ACKNOWLEDGE`
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
- `CLIENT_ACKNOWLEDGE`
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
- `DUPS_OK_ACKNOWLEDGE`
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-04-27 17:32:30 -04:00
|
|
|
Apache ActiveMQ Artemis supports two additional modes: `PRE_ACKNOWLEDGE` and
|
2014-12-04 10:25:29 -05:00
|
|
|
`INDIVIDUAL_ACKNOWLEDGE`
|
|
|
|
|
|
|
|
In some cases you can afford to lose messages in event of failure, so it
|
|
|
|
would make sense to acknowledge the message on the server *before*
|
|
|
|
delivering it to the client.
|
|
|
|
|
2015-04-27 17:32:30 -04:00
|
|
|
This extra mode is supported by Apache ActiveMQ Artemis and will call it
|
2014-12-04 10:25:29 -05:00
|
|
|
*pre-acknowledge* mode.
|
|
|
|
|
|
|
|
The disadvantage of acknowledging on the server before delivery is that
|
|
|
|
the message will be lost if the system crashes *after* acknowledging the
|
|
|
|
message on the server but *before* it is delivered to the client. In
|
|
|
|
that case, the message is lost and will not be recovered when the system
|
|
|
|
restart.
|
|
|
|
|
2015-02-25 08:37:19 -05:00
|
|
|
Depending on your messaging case, `preAcknowledgement` mode can avoid
|
2014-12-04 10:25:29 -05:00
|
|
|
extra network traffic and CPU at the cost of coping with message loss.
|
|
|
|
|
|
|
|
An example of a use case for pre-acknowledgement is for stock price
|
|
|
|
update messages. With these messages it might be reasonable to lose a
|
|
|
|
message in event of crash, since the next price update message will
|
|
|
|
arrive soon, overriding the previous price.
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
> **Note:**
|
2014-12-04 10:25:29 -05:00
|
|
|
>
|
|
|
|
> Please note, that if you use pre-acknowledge mode, then you will lose
|
|
|
|
> transactional semantics for messages being consumed, since clearly
|
|
|
|
> they are being acknowledged first on the server, not when you commit
|
|
|
|
> the transaction. This may be stating the obvious but we like to be
|
|
|
|
> clear on these things to avoid confusion!
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Using PRE_ACKNOWLEDGE
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2017-08-31 11:43:56 -04:00
|
|
|
This can be configured by setting the boolean URL parameter `preAcknowledge`
|
|
|
|
to `true`.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2017-08-31 11:43:56 -04:00
|
|
|
Alternatively, when using the JMS API, create a JMS Session with the
|
|
|
|
`ActiveMQSession.PRE_ACKNOWLEDGE` constant.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2018-03-08 15:46:38 -05:00
|
|
|
```java
|
|
|
|
// messages will be acknowledge on the server *before* being delivered to the client
|
|
|
|
Session session = connection.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE);
|
|
|
|
```
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Individual Acknowledge
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
A valid use-case for individual acknowledgement would be when you need
|
|
|
|
to have your own scheduling and you don't know when your message
|
|
|
|
processing will be finished. You should prefer having one consumer per
|
|
|
|
thread worker but this is not possible in some circumstances depending
|
|
|
|
on how complex is your processing. For that you can use the individual
|
2017-08-31 11:43:56 -04:00
|
|
|
acknowledgement.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
You basically setup Individual ACK by creating a session with the
|
|
|
|
acknowledge mode with `ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE`.
|
|
|
|
Individual ACK inherits all the semantics from Client Acknowledge, with
|
|
|
|
the exception the message is individually acked.
|
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
> **Note:**
|
2014-12-04 10:25:29 -05:00
|
|
|
>
|
|
|
|
> Please note, that to avoid confusion on MDB processing, Individual
|
|
|
|
> ACKNOWLEDGE is not supported through MDBs (or the inbound resource
|
|
|
|
> adapter). this is because you have to finish the process of your
|
|
|
|
> message inside the MDB.
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Example
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2018-03-09 10:07:38 -05:00
|
|
|
See the [Pre-acknowledge Example](examples.md#pre-acknowledge) which shows how
|
|
|
|
to use pre-acknowledgement mode with JMS.
|