Hanumath
Hanumath

Reputation: 1117

How to implement HTTP request queue in Java

we are trying to setup Architecture for Application.This is first time for us.This Application is not interact with End-Users,it's for my internal computations purpose. We have a remote DBServer(Ms sql server azure) with 1 database name as DBTesting. Whenever any data was modified in DBTesting,it triggers java Application name as App1 .

Question 1:

What are the possibilities to trigger App1 .

In App1, I am running .exe file,which is written in C language.It takes 20 min for evaluation. If DBTesting is modified many times with in 20 min, it sends that many number of requests from DBTesting to App1.But I don't want to handle more number of requests at a time.So I want to trigger App1 in queue base. Once previous Http request is done then only Queue will be release next HTTP request.

Question 2:

Is there any way to Implement this using Java or any other technologies

we are interacting Database with this Link

UserName : MyUserName

Password : MyPassword

we are trying to fix these from 1 week,but we are not figure it out which way is good way.

can anyone suggest me with some tutorials, which are suitable to my requiments.

Thanks.

Upvotes: 2

Views: 4303

Answers (2)

Learn More
Learn More

Reputation: 1561

You can use Active-MQ for queuing. Active MQ, Hello World

If you are using MSSQL service broker, it already provides Message Queues. you just need to figure out how to use it properly in your case.

This is link to Service Broker to JMS bridge.

  • You do not need to invoke any application via Database.
  • C program is taking 20 minutes to process each HttpRequest.

Use following steps:

Part 1:

  • p1.1 - Setup a queue using MSSQL service broker.
  • p1.2 - Each time database changes, send a message to queue.

Part 2:

  • p2.1 - Have a Java program which polls queue and checks if there are any messages.
  • p2.2 - If there are no messages, it sleeps for some time.
  • p2.3 - If there are new messages, it just takes one.
  • p2.4 - The message, is passed to C program by Java program(see Process Builder ) .
  • p2.5 - Wait for the process to complete.
  • p2.6 - When process completes(after 20 minutes ), go to p2.1.

This link might help you indirectly.

Since Azure does not support service broker, there has to be other way to implement part1.


Part1 (Implement below steps in way possible ):

  • Step 1. Generate request-data(not message, just data) when database changes.

    I want to send modified or new data with request from DB to Java Application

    • I need to know how/where data is generated/gathered when database changes. Only this much in this step. Once this is clear, then we will forward. Please take one step at a time. -
  • Step 2. Create messages from data generated.

  • Step 3. Read messages and send them to queue.

    send messages including data to Queue

    message Structures:

    The following message points to Application1.

     App1?data="1,2,3,4,5,6,7,8,9,10..."
    

    The following message points to Application2.

     App2?data="1,2,3,4,5,6,7,8,9,10..."
    

    If it allow to mention our own custom message,then I will create one more table in DB.This table have 2 columns.1 row points to ApplicationName and 2 row points to message Name.It is useful while forwarding time.

Part 2(As of now remains same):

  • p2.1 - Have a Java program which polls queue and checks if there are any messages.
  • p2.2 - If there are no messages, it sleeps for some time.
  • p2.3 - If there are new messages, it just takes one.
  • p2.4 - Java Application imports XMl file and based on message context it will send http request to that corresponding Application including data
  • p2.5 - The message, is passed to C program by Java program(see Process Builder ) .
  • p2.6 - Wait for the process to complete.
  • p2.7 - When process completes(after 20 minutes ), go to p2.1.

Xml Structure is in the following way.

   <Message>
     <Message-Body>
       <Message-Context>App1</Message-Context>
       <URL>`http://localhost:8080/App1`</URL>
     </Message-Body>
     <Message-Body>
        <Message-Context>App2</Message-Context>
        <URL>`http://localhost:8080/App2`</URL>
     </Message-Body>
   </Message>

Upvotes: 1

Felquir
Felquir

Reputation: 441

The easy way would be have a table in your DB with the Http Requests and a program running queries, when finds a result make the request if not sleep.

while(true){

//query the DB
if (have_results){
         //http request
         // remove request from the DB

 }else{
     // sleep 1s

}

}

it isn't code but It should be easy.

Thanks

Upvotes: 0

Related Questions