I have a java module in my android 5.1 application that has to communicate with a remote control unit device which makes available only a WebSocket interface and a "subscription" mechanism to receive updates on the current state of some sensors physically connected to the control unit.
What I need to do is:
request a Json web token
connect to the control unit websocket with the retrieved token
once connected, make a subscription request for sensors's status
waiting for updates from control unit (json response messages)
update my android app status based on response received
I've looked for libraries to use and I found Jetty and JSR 356.
My Java module is written in Java SE 8.
What kind of implementation is possible to use ?
I need to implement a ServerHandler to manage the session status and possibile reconnection actions or a WebSocket listener only to receive updates ?
Any code sample reference or tutorial are well accepted.
Related
I am currently working on a POC where I am draining messages from an azure queue - that is populated through a dynamics CRM plugin during DB CRUD operations.The queue drain operation using a java client fails with the message :
<Error>
<Code>500</Code>
<Detail>
The service was unable to process the request; please retry the operation. For more information on exception types and proper exception handling, please refer to http://go.microsoft.com/fwlink/?LinkId=761101. TrackingId:add85f1a-a249-4e69-b284-ad879cd29968_G27, SystemTracker:scsqueue1-ns:Queue:scsqueue1, Timestamp:7/6/2016 7:21:49 PM
</Detail>
</Error>
The java client can be found here :
https://github.com/sharpcodes/scs-bus-demo
However using a C# client works
I can't see the obvious issue in your code on GitHub. However, per my experience, I suggest that you can try to use the tool Fiddler for debugging the rest request from your code, because the Azure Service Bus SDK for Java is wrapped the REST APIs, such as Receive and Delete Message (Destructive Read) for draining messages.
Meanwhile, there are three ways below in Java for draining messages via the operation Receive and Delete Message on Azure.
Using Azure Service Bus SDK for Java, please refer to the section Receive messages from a queue of the tutorial "How to use Service Bus queues" to do with default mode ReceiveAndDelete.
Using Azure Service Bus REST API for Java with http client, please refer to the section Receive and delete a message from the queue of the tutorial "Service Bus brokered messaging REST tutorial".
Using JMS API with AMQP 1.0 in Java, please refer to the section Coding Java applications of the tutorial "How to use the Java Message Service (JMS) API with Service Bus and AMQP 1.0" to see the function SimpleSenderReceiver().
Thanks to peter for guiding on this..
Looks like there is an issue with the dynamics crm-azure bus plugin that prevents java/node-js clients from draining the queue using SDKs or RestFul calls.
Using JMS client seems to do the trick. Another way would be to have a C# middleware that could be wrapped by Java/Node.
Here is the reference to the issue : https://github.com/Azure/azure-sdk-for-php/issues/823
The issue is closed now as a fix had to be made by Azure Java SDK team to escape characters correctly..
I have an application that contains order data . I want to send this to all users of this app as notification.My target is to send Push Notifications to all of the users of my applications. How would I accomplish that?
To begin with your app mush already be using GCM and listening to the correct topic. Otherwise you have to roll out an update with the new GCM feature and hope that all users update it.
If you want to see some code for this take a look at this sample i crated some time ago. What you need to implement from the sample is the "SubscribeTopic" part. And to test if its working you can use this java program.
The good thing about topics is that you don’t need to save the users registration tokens and the message is sent to everyone listening for that exact topic.
Use Apache kafka
The original use case for Kafka was to be able to rebuild a user
activity tracking pipeline as a set of real-time publish-subscribe
feeds. This means site activity (page views, searches, or other
actions users may take) is published to central topics with one topic
per activity type. These feeds are available for subscription for a
range of use cases including real-time processing, real-time
monitoring, and loading into Hadoop or offline data warehousing
systems for offline processing and reporting.
To start with, note that a full GCM implementation requires both a client implementation and a server implementation. Before you can write client apps that use GCM, you must have an application server that meets the following criteria:
Able to communicate with your client.
Able to send properly formatted requests to the GCM connection
server.
Able to handle requests and resend them using exponential back-off.
Able to securely store the API key and client registration tokens.
Note: never include the API key in any client code.
For XMPP, the server must be able to generate message IDs to uniquely
identify each message it sends (GCM HTTP connection server generates
message IDs and returns them in the response). XMPP message IDs
should be unique per sender ID.
Complete documentation, how-to-guides for sending messages and links to examples can be found from Cloud Messaging - Messaging Concepts and Options.
You may also check ANDROID AND GCM – BROADCAST YOURSELF for the tutorial and demonstration on the use of GCM for the broadcast of messages to an Android client from a Tomcat server and use of sending broadcastintents from a service and receiving those broadcastintents from an app's activity.
I have a requirement:
I have to customize a push notification to the subscribers when a service changed.
I googled and found only IOS, android have the function with their platform,but that's not what I need. I'm using the play2.
how to do that?
With play2, the way to go is to push data to the client browser using either Server Sent Event or Websockets. Play supports both technologies.
WebSocket will allow you to have a two-way communication whereas SSE only have one way. For more information, I invite you to follow the documentation here for Scala or for Java
I think I'm just missing a little detail that is preventing me from seeing the whole picture.
I have a web application which use ajax request every x time to update client with new information or tasks.
I also have a long running process on the server which is a java computation engine. I would like this engine to send update to the client.
I am wondering how to migrate my web app to using websocket. Probably phpwebsocket or similar. Can my server 'decide' to send information to a specific client? It seems possible looking at the php-websocket.
Can my java backend long process use the websocket server to send notification to a specific client. How? well I can say that my java app could use a class that could send over websocket instead of http.
But how the websocket server knows to which client to send the 'info'. I am puzzle by all this. Any document that explain this in more details? It seems that the websocket could create an instance of my web application.
Thanks
Your server, which will have an arbitrary number of active client sockets, decides which ones to write to (possibly in response to input from the user).
phpwebsocket (which is still very rough around the edges) has a User class with $id, $socket (this is the underlying TCP socket), and $handshake fields. You could extend that class with additional metadata about the User (e.g. a computation identifier). Or you could use an array mapping from computation id to User.
Perhaps when Java computation n finishes, you can look up the socket associated with that computation, and write to its socket.
I'm implementing a client-server GPS application. Client side is a J2ME midlet that sends GPS location via HTTP/XML to a Java Webservice (Tomcat servlet). The servlet stores positions in SQL database. The other client app is a web browser that can login and see the actual position of midlet using Google Maps. This client is written using GWT. All is deployed on the same Tomcat container. Now I'm wondering how to dynamically update current position in webrowser Google Maps of the mobile so that the client can see how the mobile moves. How to do it in GWT - should I create a timer object in GWT client and asynchronously send HTTP request to server for getting the actual positions? Or is there any mechanism in AJAX/GWT to notify client (web browser) about the data update?
Thanks
Dominik
Regardless of all the talk about "push", the standard HTTP model is still one where the client has to ask the server for updates.
In a GWT app, you should use the well-supported Ajax functionality to request small-granular updates (polling, I guess) from the server at regular intervals (5 seconds, maybe?) and use the newly obtained information to update your map info.
There is a detailed article on the GWT incubator web site about Server Push and how to achieve it with GWT. From the article:
Explains Server Push, sometimes known as 'comet', and how you can achieve this with GWT.
Then, if you take a look at the comments, you can find interested related information and open implementations as gwt-comet, GWTEventService ...
I agree with rok.
If your deployment is going to be small enough to be able to support one permanent connection per web browser client go with Server Push/ Hanging RPC/ Long Polling or whatever you want to call it.