I have a database in my sql and I have multiple clients using that database.
whenever a column in the database is updated I want to call the corresponding java method on the client side. Basically this is the message system, when user get new message I want to give him a notification. Is this the right way to do it? If yes how do I implement it. If not what would be the right way to do it?
Any help appreciated
Thanks
There are messaging frameworks for such reason for example :
Jabber
UDP multicast (http://download.oracle.com/javase/1.4.2/docs/api/java/net/MulticastSocket.html)
JMS (http://activemq.apache.org/)
No, this is not the right way to do it. To send messages, use message-oriented middleware (MOM), using JMS. There are free JMS implementations available (like ActiveMQ, for example).
You might find interesting the following blog post and thread: http://www.unlimitednovelty.com/2009/04/twitter-blaming-ruby-for-their-mistakes.html
The blog was written when Twitter has changed its messaging system platform from Ruby to Scala. It generated an ineteresting flame about messaging systems between experts...
Related
I am creating an app using React-Native for the front-end, Java for the back-end and PostgreSQL for the database.
One feature of this app is to allow users to add each other as friends and instant message them - just like other social networks. At the moment, security is not a priority but I don't want to create something that I will have to completely redo when I do have to make it secure!
The goal here is to give each user the ability to send/receive messages to/from their friends. They also need to be able to view the message history with each contact.
I just need some advice on the following points to get me going as I haven't gotten very far on my own:
How should I send messages from the front-end, to the Java server and then to the receiver? This will involve the app having to listen for new messages so would the Socket.IO library be the way to go for this?
How I should store the messages in the database? E.g. have a table for messages with user_ids to be used for retrieval?
I should point out that I am very new to React-Native, databases and networking so I am finding this very challenging!
I will massively appreciate any help and any examples would be fantastic!
You should use WebSocket on the server. Spring supports it
Here's a tutorial I wrote about sending messages from PostgreSQL to the browser using WebSocket, which isn't exactly what you're going to do, but can hopefully get you started:
http://blog.databasepatterns.com/2014/04/postgresql-nofify-websocket-spring-mvc.html
We are developing an app that will have Web service in JAVA and Application in iOS.
Web-service will compute the list on a Particular Algorithm and that list has to be Shown realtime on the Device.
We were thinking of making a Routine Post Calls on every minute and get result from server but I think this would be very Costly and inappropriate way for syncing data with the Web-service's Result.
Can anyone provide Best alternative and Ideal Way for such type of requirement. Which approach should we choose to Provide such Real-time Sync for application.
You can use a WebSocket connection for this. WebSocket establish a full duplex connection between iOS and your server. This allows the server to trigger the client if new data is available.
As you mention it doing a routine post call every minute could work, but it will cost a lot of resources. It's not a good solution.
One solution could be to use websocket. So the server will send notification when data have changed. See here what is websocket http://fr.wikipedia.org/wiki/WebSocket
Use netty-socketio java realtime framework, it supports long-polling and websocket transports. javascript, ios, android client libs also available.
After googling and research, I found Socket.io better option for Our case
Socket.IO is a WebSocket API created by Guillermo Rauch, CTO of LearnBoost and lead scientist of LearnBoost Labs.
Socket.IO will use feature detection to decide if the connection will be established with WebSocket, AJAX long polling, Flash, etc., making creating realtime apps that work everywhere a snap. Socket.IO also provides an API for Node.js which looks very much like the client side API.
Is it possible that a java program is running and it works on commands from another java program simultaneously running in same machine? For example: if a second java program sends a query database command to first running java program, the first one will execute a query in the database connected to it and reply back to second one.
Please help.
Thanks in advance.
You could use socket programming to do this.
Make a server and make it listen to incoming messages.
http://docs.oracle.com/javase/tutorial/networking/sockets/
You could learn about sockets from the above link.
It is possible.
Socket programming is good but in this case you have to implement synchronization and multi threading request handling.
Another way is using web service for storing data in db.
http://docs.oracle.com/javaee/6/tutorial/doc/gijvh.html
Probably you can use any of
remote invocations (RMI), see http://docs.oracle.com/javase/tutorial/rmi/
or
manged beans (JMX), see http://docs.oracle.com/javase/tutorial/jmx/
As already answered you can use socket proramming but you would have to implement your own protocol.
It should be easier to use RMI which lets you invoke remote methods as if they were local but it is limited to java.
A "bit" heavier (in resources and implementation) solution is using web services but it is a standard which is not limited to java world.
You can also use JMS but I think it should be overkill (you need a server such as activeMQ)
Purpose:
I'm trying to make a real-time web service in Java. When there're changes in database, the data in clients(probably Android client) will be changed automatically without refreshing.
Platform:
I'm using Tomcat 7 container and Axis2.
Problems:
I'm stuck in the way to approach. I've realized that there were 2 ways:
1. When the data in server changes, notice to all the clients. Web-service allows us to do this, but I don't know what clients I have to inform!
2. Clients connect to the server, keep the connection alive and whenever there's a change, update data. However, if the client is the handheld, it will consume much power and data exchange over 3G network.
I know that's a complicated problem. So I just want to ask if there is an efficient way to approach? And if possible, anyone can give me one example of realtime web service like this?
I've searched over many pages, but nothing's helpful. Can anyone give me some suggestions? Tkx!
Is it a requirement to use webservices or Axis? Otherwise, you might be interested in WebSockets. These are connections over plain HTTP that provide two way communication. Your clients will connect to your server, and as soon as new data is available your server can push data to every connection it knows of, thus informing all clients that are connected.
I'm looking for a library that will allow me to deliver simple text events from the server to the clients via sockets. Something simple and lightweight. I can write it myself, but decided to check if such thing exists first. The idea is that there's an application that generates events (such as order rejected or an internal error occurred) and acts as a server. Those events must be delivered to all connected clients in real-time. And a client is just a tray-icon app that pop ups the said event's text. Some simple UDP client/server. Does anyone know if there's a library out there for Java?
Thanks!
There are many possible solutions, but if you want simple I suggest you try Hazelcast
It is as simple as using java.util.{Queue, Set, List, Map}. Just add the hazelcast.jar into your classpath and start coding.
This could be easily accomplished with XMPP pubsub. You can use Smack to connect to the server of your choice that supports pubsub (OpenFire, ejabberd, ...) so your application that creates the events is the publisher and the clients are all subscribers. It will require a 3rd party server to be used (many are open source), but it is just a single library for all client access. I have experience with OpenFire and it can be set up in about 15 minutes.
Many will not consider this light weight, but rolling your own pubsub solution is really not necessary.
You should check out JBoss Netty and/or Apache MINA, which are both frameworks for building network protocols. It's debatable whether you consider them simple, although you can certainly build lightweight implementations with them.