2

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.

Hanumath
  • 1,117
  • 9
  • 23
  • 41
  • @All Is it possible using `Thread` concept. – Hanumath Aug 02 '13 at 06:39
  • In above question, if you give details of database(atleast server name) and some thing more related to application, it might be easier to answer. Diagram will help a lot. – Learn More Aug 02 '13 at 12:37
  • @LearnMore I updated my question.can you check it once. – Hanumath Aug 05 '13 at 11:32
  • I updated my answer. If it is possible for you to create a queue using MS-SQL service broker and read that queue via from an external application, I think it will work for you. – Learn More Aug 05 '13 at 12:06
  • We chatted and clarified. Were you able to get it done ?? – Learn More Aug 13 '13 at 15:14
  • While chat time, I said messages are sent from `DB` to Java Application(Which App is running .EXE file). Db part was done by one of colleague. So just for my testing I wrote one more Java class for sending text messages to `Activemq` name as `MessageSender.java`.It's working fine.I tried to write another java class for receiving messages from `Activemq`.But I am getting all the messages at a time.Still I didn't figure it out.For this I post the following link `http://stackoverflow.com/questions/18128089/how-can-i-push-messages-from-activemq-to-java-application`.check it. – Hanumath Aug 13 '13 at 18:08
  • added answer. Please check. – Learn More Aug 14 '13 at 06:02

2 Answers2

1

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>
Learn More
  • 1,535
  • 4
  • 29
  • 51
  • you mean `JMS` queue send request to `App2` or `App2` will read from JMS Queue. I never work on `JMS`. – Hanumath Aug 02 '13 at 11:04
  • JMS queue will only act as a channel of communication between DB and APP2. You can write code in both applications to send and receive to/from queue. If you have not worked on it, do not worry. It is as easy as creating an object and passing it to a function, with some concepts from Serialization :) . – Learn More Aug 02 '13 at 11:08
  • If you don't mine can you suggest me with any tutorials. – Hanumath Aug 02 '13 at 11:26
  • Start with Serialization in JAVA. Then check Apache Active MQ tutorial. If you have problem, just post here. – Learn More Aug 02 '13 at 11:32
  • BTW, how do you check if DB is modified and how the request reaches APP2 as of now ? – Learn More Aug 02 '13 at 11:42
  • using Service broker concept I can send `Http` requests from `DB` to any Application.That means Instead of browser I am triggering Applications by `DB`. – Hanumath Aug 02 '13 at 12:03
  • I am sorry asking this question, Am I need to write any `Java` code for creating `JMS` Queue,sending messages to Queue.... don't mine, I am new to Java Technology. – Hanumath Aug 02 '13 at 12:19
  • Yes you need to. Your flow is not clear. Please update information in question. Comments are not suitable for this. – Learn More Aug 02 '13 at 12:23
  • @All I updated my question with clear details,can you check it once. – Hanumath Aug 05 '13 at 11:40
  • I installed `Activemq` and open Activemq console page in browser.After that I am not sure what will I do.I didn't understand flow of `JMS` working from your links. – Hanumath Aug 07 '13 at 04:59
  • I can guide step by step. But I am not sure if you need AMQ. What you need is to Create a Queue via MS-SQL Service Broker and poll the queue via Java program. – Learn More Aug 07 '13 at 06:58
  • Initially I thought to create Queue via MS-SQL Service Broker,but `MS-Sql Server Azure` not supported `Service Broker`.So I think to divide my work into 2 parts. 1 part corresponds to sending messages to `Activemq` in any way from `MS-SQL Server Azure`. 2 Part corresponds to pushing messages to Java App name as `App1`,here it decide These message corresponds to which Application. may be you get doubt how `App1` decide.For this I use XML file. I think If I do like this later If I want to add Apps just I need to change XML code. `@Learn More` what did you say on my idea is it efficient way. – Hanumath Aug 07 '13 at 10:13
  • First challenge is to successfully share messages between application. Once that is achieved, then we will worry about any other thing. How you are going to implement part 1 ? – Learn More Aug 07 '13 at 11:04
  • Really I don't have any idea,I think 2 part is easy to implement so I think to start that.For this I create messages manually in `Activemq` console.Really `@Learn More` my mind is not working because of this challenge. – Hanumath Aug 07 '13 at 11:45
  • I am starting to put steps in my answer. I will put comment. You edit and add a response. It is not easy to follow in comments. – Learn More Aug 07 '13 at 11:49
  • `@Learn More` Am I need to edit your answer or my question according to your answer. – Hanumath Aug 07 '13 at 12:23
  • Please add at places where I wrote comment here. Use your own fonts. Do not edit what I have written. – Learn More Aug 07 '13 at 12:52
  • I modified.Sorry I added one more `p2.4` in part2 for your better understanding, what I am thinking. – Hanumath Aug 07 '13 at 14:39
  • @user2642355 Please take one step at a time. As of now part1>step1. Is that clear ? – Learn More Aug 07 '13 at 14:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35010/discussion-between-user2642355-and-learn-more) – Hanumath Aug 07 '13 at 14:54
0

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

Felquir
  • 431
  • 1
  • 4
  • 12
  • I want to pass parameters with `Http` request.That parameters will be change dynamically. If you change configuration in `Application server`,It can also allow only 1 request at a time. Compared to `DB Table` it is very easy.But why I am doing this using `Java`,If I want to change anything later,I can easily modify my code.It's like maintainability issue. So I want to implement in Java.I hope you understand What i am trying here. – Hanumath Aug 02 '13 at 08:48
  • As far your suggestion, If I make a table in my `DB`. How can I know wheather previous request is it completed or not ? – Hanumath Aug 02 '13 at 12:21
  • If you make a table for the request, and another for the parameters for each request, you don't need to change it each time. – Felquir Aug 02 '13 at 14:57
  • If are queering the database all the time, when the program get a request just execute and delete the request. – Felquir Aug 02 '13 at 14:59