Java EE 7 Application Developer — Question 46
You are working with JMS publish-subscribe operations.
What happens when a producer publishes a message to a topic for which a durable subscription exists but there are no subscribers available?
Answer options
- A. The publisher waits for a subscriber, who then consumes it. However, the publisher will time out if no consumer arrives within the given timeout period.
- B. The publisher sends the message. However, it is never consumed because there wasn't anything listening when it arrived, regardless of the message timeout length.
- C. The publisher successfully sends a message, which will be consumed later, once there is a subscriber, assuming the message hasn't timed out.
- D. The message publisher is immediately notified about the lack of subscribers and can decide for itself if, and when, to resend.
Correct answer: C
Explanation
The correct answer is C because a durable subscription ensures that messages are stored until a subscriber is available to consume them, as long as they have not timed out. Option A is incorrect because the publisher does not wait indefinitely; it will send the message regardless. Option B is wrong since the message will be stored for future consumption. Option D is incorrect because the publisher is not notified about the lack of subscribers in this context.