-
Aug 3rd, 2010, 09:50 AM
#1
JMS Item Writer/Reader example
I haven't found a definitive answer to this, and before I got further, thought I'd take a shot to see if others have done this:
I'm being tasked with trying to reuse an existing system whose only interface is asynchronous and queue-based, I'm wondering if the following is possible:
Step 1: read some data and build a message. Step 2: Drop message on queue using JMSItemWriter. Step 3: Wait for message to come back using JMSItemReader on the response queue. Step 4: Do some other stuff ... Rinse and repeat, a few thousand times a day.
Or in other words, essentially using Spring Batch to force synchronous interaction with an asynchronous resource. I'd like to make sure before I get further in research, that this is A) possible, and B) not shameless abuse of the framework that will cause major headaches down the road.
It seems like this is possible, and possibly may be one of the uses of JMS Item Reader/Writer.
-
Aug 5th, 2010, 11:28 AM
#2
The bit where you "wait for message to come back" is something you'd have to implement yourself (but Batch has a Poller interface and one simple implementation that we use for simliar purposes internally so you might find that useful). Unless you need the other features of Spring Batch though, it might be simpler to just use Spring JMS or Spring Integration (the latter for an extra level of abstraction).
-
Aug 10th, 2010, 01:39 PM
#3
My apologies - I had meant to respond sooner. Thank you very much for the reply. We're going to start prototyping a solution similar to what you've described. Thanks again.
-
Dec 8th, 2010, 10:04 AM
#4
Sending Synchronous Messages in the itemProcessor
Hello,
i want to send synchronous Messages on the JMS Queue, but to implement this in the itemProcessor. Anyone has an idea how i can go about this, or is there an example anywhere which shows how one can do this? I will be very grateful for any prompt response. Thank you in advance.
Best regards
-
Dec 8th, 2010, 10:19 AM
#5
I was additionally crippled by XA requirements, and a few other things. I chose not to use the poller interface, and instead implemented a set of parallel tasklets that did the following:
tasklet 1:
-reader: read from database
-processor: put message on queue and got correlation id
-write: correlation id to database
tasklet 2:
-reader: read from queue
-processor: find record to correlate with and update
-write: persist updated data from processor
I was able to control when the second tasklet ended by using a JMSTemplate timeout, which when a timeout occurs, returns an empty object to the reader. If I remember correctly, if the reader method returns a null value, the tasklet ends gracefully.
Not saying this is the *best* implementation, but worked for me given the scenario I was in.
-
May 12th, 2011, 07:10 AM
#6
I am kinda of looking for same scenario in Spring Batch. Is it possible for you to provide sample implementation that uses JMS?
Thanks in advance
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules