liveBook · Manning

Pull model

As explained in Spring in Action, Sixth Edition

A pull model is a messaging consumption pattern in which a consumer explicitly requests or retrieves messages, potentially waiting until one is available.

A pull model lets a message consumer explicitly request a message. The request may return immediately or block the calling thread until a message becomes available. section 9.1.3

With Spring JMS, JmsTemplate provides the pull-based client. Its receive methods return a raw Message, while receiveAndConvert methods use a configured converter to produce a domain object. section 9.1.3

A consumer can request messages in several forms:

  • Receive from the default destination, a Destination object, or a named destination. section 9.1.3
  • Retrieve a raw JMS Message with receive, then convert it explicitly. section 9.1.3
  • Retrieve an already-converted domain object with receiveAndConvert. section 9.1.3

Pulling an order from a queue

A JMS order receiver calls jms.receiveAndConvert("tacocloud.order.queue") and casts the result to TacoOrder. The receiving method controls when it is ready to process another order, rather than receiving callbacks automatically. section 9.1.3

Message receive() throws JmsException;
Message receive(Destination destination) throws JmsException;
Message receive(String destinationName) throws JmsException;
 
Object receiveAndConvert() throws JmsException;
Object receiveAndConvert(Destination destination) throws JmsException;
Object receiveAndConvert(String destinationName) throws JmsException;

Browse the JmsTemplate receive and receiveAndConvert signatures for the available destination and conversion options. section 9.1.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains blocking retrieval, destination choices, and conversion, but stops short of broader listener implementation details.
Examples
Uses TacoOrder messages pulled from the tacocloud.order.queue destination with receive or receiveAndConvert.
What it assumes
Assumes JMS destinations and message converters while defining pull and push consumption through concrete receiving methods.
What you can do after
Operate/configure a JMS consumer that retrieves raw messages or converted domain objects through JmsTemplate.
How it connects
Connects JMS, JmsTemplate, message brokers, message conversion, and the push model.

Also explained in

Compare how 4 books explain pull model →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.