I'm starting out with Grails and want to build a sample application.
Below is the flow of the application I'm envisioning. I'll follow up with questions.
The flow of the app:
User uploads a file
controller gets the file and just sends a response back saying "uploaded"
File is put in a JMS queue
Java service running separately fetches the file from the queue and processes it (just reads the first word)
Java service puts the response back (where does it put the response?)
Grails App will read the response and present it to the user
Questions
Where does the java service put the data after reading the file?
How does the grails app read the data put by the java sevice?
Is there something missing from my understanding? I plan to use grails jms plugin and ActiveMQ
Can something be improved in this architecture? This is a prototype I'm putting together for a bigger application.
I would really appreciate any articles/tutorials on an example of a simple app like the one above...?
In you case JMS is used in a synchonous way, so it depends on your JMS provider if you can do this. If the JMS provider is able of doing synchronous communication you put the answer after the file processsing into a reply queue.
In the synchronous JMS way, the java service will wait for a response from the JMS provider so can can present the response from the service back to the controller and then to the user...
So..:
User uploads a file
controller gets the file and just sends a it to the JMS queue and waits for response!
Java service running separately fetches the file from the queue and processes it (just reads the first word)
Java service puts the response back in a reply queue
Controller wil get the response reads the response and present it to the user
Your page could be a nice ajax page that presents the user with a processing spinner.
Related
I am developing a servlet based application. One situation is that a client requests some data from a database which is sent back in the form of html. The client will modify this data and then sent it back to the server. Now the twist starts. There is not a single client. So multiple clients can request the same data. So what I am doing is that when the first client makes a request, this request is stored somewhere so that when the next user makes the same request he is denied the data.
Now suppose the first user gets the data and 2nd is denied. Now while the first user is on the html page which allows him to modify the data. I want to send continuous javascript async post requests at a fixed interval to inform the server that the client is active.
At the server side I need a thread or something which can keep waiting in a loop for the javascript async requests and if the request is not received within the fixed time then the thread removes the saved request so that future requests to the data will be accepted.
I have searched the entire day and looked at things like async servlets, ServletContext listener and scheduledExecutorservice. I dont want to use scheduledExecutorService as it is invoked at app startUp which I dont want to do since this specific situation is a minor part of the code and to handle it I dont want something running all the time. I need some background service which keeps running even after the server has returned requested data.
Servlets won't fulfill your requirements, therefore you should use WebSockets.
As per my understanding, you are trying to push data from the server, therefore you need to a push architecture instead of pull architecture (Servlets are based upon pull architecture).
Java has native support of WebSockets
You can find several tutorials on how to use WebSockets in a Java Web Application.
Here is a link to a basic WebSockets Tutorial.
Hope this helps
I am working on a JADE project and I want to build a React app to interact with my agents.
I would like to send messages to specific agents from my web client using REST. I know that it is possible to send POST requests, but what the body should look like ?
if you create an agent programmatically you can sent message to the agent by means of AgentController.putO2AObject, but you need server code that processes your rest message and delegate it to the agent.
Otherwise you can just create java.net.ServerSocket in agent code and sent any message you want from your client
take a look at these https://www.iro.umontreal.ca/~vaucher/Agents/Jade/primer2.html and https://jade.tilab.com/doc/tutorials/JADEAdmin/startJade.html.
You may one to create the agents using pure java and invoke it from the UI using React via REST or MVC.
I have a Java Play Framework 2.5 project where periodically I have to update the registries of our customer. I can't do a simple SQL insert/update because I to do some logic and operation on every single row.
I ended up uploading on my website an xlsx file (asynchronous way) with JS and then working on it with Apache POI.
My only problem is that I don't know how to inform the user who uploaded the file on the progress of the processing of the file.
I'll like to simple show every 10% a message with the percentage.
I've searched on the net, I think the best way is to use websockets with Akka (BroadcastHub), but i'm only finding examples in Scala or for 2-way communication that send output only when an input is received.
If you know a different way to do it you are welcome!
I suggest you look at https://github.com/playframework/play-java-websocket-example : It gives an example of a websocket and an actor interaction.
In your case, you would create a named actor (useractor-someid), which manages the mutations. The controller then would reference the same actor (or have an other actor send to useractor-someid), so that it can fetch the status. I suggest you use a JsonNode flow, so you can send / receive JSON in the websocket connection.
I currently am developing a semi-simple chat app. I want the user to be able to communicate with one other person in a private chat. Just plain text will be sent. Currently my system calls php scripts from a webpage, passes in parameters and then parses the data returned. I have it so that the client sends the message, which calls a send message script on my webserver, the script then makes a message file on the webserver and then returns a success or failure back to the client. Then for the client to view this message, it would have to call a script that checks the server for a message file with a message for him. If it finds one, it sends the message back, if not, it sends a response about not having messages.
This technique works perfectly besides the fact that the client either would have to manually refresh to check to see if he had messages, or a background thread would have to refresh every few seconds. That would be fine, however that would use data if the user was on a mobile network. Not to mention the kind of resources a background loop would pull if it was refreshing at a speed that would be convenient.
So, I decided on a second idea, this would be a server programmed in Java, which would communicate over sockets. The user would send the message as a packet over the socket and the server would check to see who it was meant to go to. If the person is online, it passes the message along to that user. However this method requires a constant connection between the client and the server and that is unreliable because what if the user is in the car and data cuts out. Or some other situation where the connection gets severed. Then it would throw errors and have to reconnect.
Anyhow, my question is which technique is better. Or are they both terrible? If so, what is the correct way of doing this? Thanks in advance.
AngularJs and Ajax will be the perfect solution for you , try to learn
for actually real time messaging Use AngularJs
If the amount of data is very less ..say 20-25 messages per day...you can REST APIs on your server to transfer actual text messages and Google Cloud messaging for pushing notifications..Recently I followed this approach to develop private chat for one of my friend.
My setup consists of a Weblogic server that runs various REST services that accepts an HTTP request from a client(an android app), reads data from a MySql database and sends this data as a response to the client.
My requirement is that the client should be notified as soon as the database is updated. I have implemented a "polling" mechanism. The client constantly sends requests and checks for any changes made in the database. However this is not a very efficient mechanism.
Can you please suggest any efficient ways of achieving this?
Thanks in advance!
One of the way to use writing a CRON job for observation of Database change.
also, SO has already discussed this topic. refer below link,
Oracle database to send notification / Invoke a java method on reaching Time specified in a column