I have followed a couple of tutorials about interactive/real-time applications using STOMP over WebSockets with the Spring framework using the messaging layer.
Example in Spring
I would like to implement the same functionality in clojure. Has anybody experience in implementing a similar application? I have been looking for documentation/examples about using these technologies, but there is nothing like the examples in clojure.
That it makes sense? Is it necessary to have an external message broker to connect the backend app and the browser clients?
I have some experience using a broker to pass messages along. However, I think it's still best to write your own http frontend for the browser to talk to. That frontend in turn can post messages to a broker (using Stomp or any other protocol). That way, you have more control and you're not tied to a message broker. For instance you can have the frontend do more than just websockets, like serve static files, or a regular HTTP interface.
But that's up to you, if the broker supports websockets, you can use that too (see for instance ActiveMQ). My advice is: try the simplest possible way first :-).
Take a look at Http-kit for a good Clojure webserver. It also has good websocket support.
Related
I'm having some troubles finding a good way to stablish a communication between my frontend and my backend.
I have a C++ app that deals with the communication with some device, I'd like that my webpage gets the request from the user, then send that request to my always running C++ app, process that request, and then send a response back to my webpage, is there any way to make this happen?
You could use Boost Asio to build a REST server into your C++ app see:
https://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/examples/cpp11_examples.html
Or you could use a C++ REST framework see:
https://github.com/Microsoft/cpprestsdk
There are a few others as well.
Finally you could build your REST/Web server using some other language such as Java or C# and use a messaging protocol to communicate to your C++ server. You could use sockets or ZeroMQ for example:
http://zeromq.org
I'm building a Clojure app that needs to interface with Slack's real time API, and that requires a connection to a Websocket.
I am aware this is possible with gniazdo, but this pulls in Jetty, and I believe that Immutant has its own Websocket abstraction.
I've also tried using clj-http, but it does not recognise the wss:// protocol, which is the URL returned from the Slack API.
Would greatly appreciate it if I were pointed in the right direction. Thanks!
Immutant uses Undertow as it's web server, which provides the wss protocol support you seek. Sadly, looking through the Immutant clojure wrapper code I don't see any part touching this functionality, so you will have to use Clojure's Java interop facilities.
The relevant source seems to be implemented here.
A client talks to Django, and django uses node.js to do some javascript related work to give back the client a http response.
I wonder how I should set up the link(?) between the django and node.js.
Simply, I could use python's requests library and talk http, but is this best I can do?
If I were to build the communication link in c++, I would create non-block socket with Send/Recv Thread and use mutex(or similar) between the django view code and the send/recv thread.
I guess that's what is called asynchronous io in node.js world.
Is there a similar thing in python so that I could use on django side to talk to another server?
I heard many big companies use Thrift, would it fit here?
I also see gevent might be relevant keyword here, but not sure.
I am not sure if my answer is still relevant, but I'll give it a try.
IMHO, the best solution for you would be to have a RESTful API for your Django app. This has several advantages:
it provides a lot of decoupling between your Django app and your Node.js one, so in case you ever want to reuse any of them or to replace one of them, it will be easy
it allows you to design an API for each of them and to hide the rest of your implementation (your Django app should not care how Node.js does its job, but only the response that it provides)
there are many great frameworks out there that can help you quickly build your APIs (at leat for Django there is Django REST framework)
If you don't want to build a RESTful API, python's request library is probably the best and easiest way.
Good luck.
Is it possible to communicate from a web browser(Loaded an HTM page from server) to an application running in the same server using AJAX. Need to send the request from browser using a button click and update the page with responses received from one another application running in the same server machine?
I am using HTML pages to create website and not using any PHP or ASP like server side scripting. In server machine data are manipulated using a C++ application.
I think you can use any sort of Javascript functions to do that. But you might need to use jQuery or similar frameworks to make your live easier. You might need to search for "Comet Programming" to know exactly how to do 2-way communication between client and server
Updated:
Well, this kind of stuff requires you to read a lot (if you have not already known). Basically, what you need is a server that can do long-polling (or eventsource, websockets). There are many open-source ones that might help you to get started. I can list a several good ones here. There are a lot more
http://www.ape-project.org/
http://cometd.org/
http://socket.io/
http://code.google.com/p/erlycomet/
http://faye.jcoglan.com/
So after you have the comet server up and running you will need to setup the client side (probably Javascript). For those listed projects, most of them come with the client side code to interact with the server (Except for erlycomet). Therefore, you can just use the examples provided and run a quick prototype. If you want to use your raspberry pi, you can use nodejs which provide a lot of ease for dealing with real-time communication (socket.io, faye). And lately, http://www.meteor.com/
I would think of the problem this way: you want to provide a web front end to an existing c++ application. To achieve this you need to think about how your web server communicates with your c++ application. Communication between the browser and web server can be thought of as a separate problem - as you say AJAX calls can be used, or maybe have a look at websockets.
Once you have your request in the web server you need to communicate it to the C++ application (and/or visa versa). This can be done a number of ways, e.g. sockets or RPC. I found this question here which has some good advice.
As mentioned here
https://github.com/blog/1174-auto-updating-comments
What is the technology behind this? If I've to add this feature in a Django powered web app, what should I use and study?
Looking at network tab it looks like they (at least with chrome) are using HTML5 Server Sent Events.
So practically the browser subscribes to a event stream and the web server just sends messages back.
I am not an expert but I guess on the server side you need to be able to keep an open connection that streams the events to the client.
I found an implementation of SSE for python here: https://github.com/niwibe/sse and a django implementation on top of that: https://github.com/niwibe/django-sse
I did not use them (yet) on any production so I suggest them only as study / poc material :)