Receives the next message produced for this {@code JMSConsumer} andreturns its body as an object of the specified type. This method may be used to receive any type of message except for {@code StreamMessage} and {@code Message}, so long as the message has a body which is capable of being assigned to the specified type. This means that the specified class or interface must either be the same as, or a superclass or superinterface of, the class of the message body. If the message is not one of the supported types, or its body cannot be assigned to the specified type, or it has no body, then a {@code MessageFormatRuntimeException} is thrown.
This method does not give access to the message headers or properties (such as the {@code JMSRedelivered} message header field or the{@code JMSXDeliveryCount} message property) and should only be used ifthe application has no need to access them.
This call blocks indefinitely until a message is produced or until this {@code JMSConsumer} is closed.
If this method is called within a transaction, the {@code JMSConsumer} retains the message until the transaction commits.
The result of this method throwing a {@code MessageFormatRuntimeException} depends on the session mode:
- {@code AUTO_ACKNOWLEDGE} or {@code DUPS_OK_ACKNOWLEDGE}: The JMS provider will behave as if the unsuccessful call to {@code receiveBody} hadnot occurred. The message will be delivered again before any subsequent messages.
This is not considered to be redelivery and does not cause the {@code JMSRedelivered} message header field to be set or the{@code JMSXDeliveryCount} message property to be incremented.
- {@code CLIENT_ACKNOWLEDGE}: The JMS provider will behave as if the call to {@code receiveBody} had been successful and will not deliver themessage again.
As with any message that is delivered with a session mode of {@code CLIENT_ACKNOWLEDGE}, the message will not be acknowledged until {@code acknowledge} is called on the {@code JMSContext}. If an application wishes to have the failed message redelivered, it must call {@code recover} on the {@code JMSContext}. The redelivered message's {@code JMSRedelivered} message header field will be set and its{@code JMSXDeliveryCount} message property will be incremented.
- Transacted session: The JMS provider will behave as if the call to {@code receiveBody} had been successful and will not deliver the messageagain.
As with any message that is delivered in a transacted session, the transaction will remain uncommitted until the transaction is committed or rolled back by the application. If an application wishes to have the failed message redelivered, it must roll back the transaction. The redelivered message's {@code JMSRedelivered} message header field will beset and its {@code JMSXDeliveryCount} message property will beincremented.
@param c The type to which the body of the next message should be assigned.
If the next message is expected to be a {@code TextMessage}then this should be set to {@code String.class} or anotherclass to which a {@code String} is assignable.
If the next message is expected to be a {@code ObjectMessage}then this should be set to {@code java.io.Serializable.class}or another class to which the body is assignable.
If the next message is expected to be a {@code MapMessage}then this should be set to {@code java.util.Map.class}(or {@code java.lang.Object.class}).
If the next message is expected to be a {@code BytesMessage}then this should be set to {@code byte[].class}(or {@code java.lang.Object.class}).
@return the body of the next message produced for this{@code JMSConsumer}, or null if this {@code JMSConsumer} isconcurrently closed
@throws MessageFormatRuntimeException
- if the message is not one of the supported types listed above
- if the message body cannot be assigned to the specified type
- if the message has no body
- if the message is an {@code ObjectMessage} and object deserialization fails.
@throws JMSRuntimeException if the JMS provider fails to receive the next message due to some internal error