Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Help with REST Web Service in Java and internal thread

 
Ranch Hand
Posts: 64
Oracle Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody, I'm facing a very difficult requirement for an application that I'm developing.

The issue is that I have a restful web service and I use only two methods: POST and GET. In addition I have a Worker Thread which can be considered as a Daemon or a background thread. The flow of the application must be that some user sends a document to my REST using the POST Method, my POST Method gets the bytes of the message, process them into a DocumentBean and I put it on a Message broker. My worker thread is the java application which will be in charge of get the message from the broker and save it in an inbox path in the server. If all the flow is completed, the worker thread will set a boolean variable to true and if not, false and my post method is supposed to return an XML with tags <Response><code>200</code><message>OK</message></Response> and if it fails, it changes the code to 500 and message Error.

I've already tested the flow using a JUnit Test, what I don't have any idea is how my RestInterface will retrieve the status of the worker thread. Inside the POST method I'm converting the bytes to a Bean type and then I'm sending it to the Message Broker, then my worker thread do all the job, but how can I notify the rest that the process is complete to send the XML Response to the cliente?

Please I'll be really grateful if somebody could help me with this. Thank you very much for your time.
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Well if you're going asynchronous through the message broker from the REST service,
then it will detach as soon as the message has been transmitted.

You would probably have to leave the service in a listening mode (a loop) and await the response
from the message processing service, so you could format the result and send it back.

Client -> REST -> JMS (Done)

Client -> REST -> JMS (Await some response, listen) -> Format response -> Client

WP
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

how my RestInterface will retrieve the status of the worker thread.



It seems to me that you want to retrieve the status of the "DocumentBean", not the Thread - after all, the Thread may be working on the next input bean from another requestl

Bill
reply
    Bookmark Topic Watch Topic
  • New Topic