UM1979
UM1979

Reputation: 162

Does CometD application needs Websocket Protocol as mandatory

I have to send account update messages to the users so that the update can be shown in the browser directly like real time updates.

Our existing application architecture is having Zuul 1.x.x Proxy, Spring boot RESTFul micro services (Just a pass through) and a 3rd party app as a back-end. Spring boot Restful services uses OAuth as a security to authenticate the requests received.

These are all established in AWS ELB and EC2 except the 3rd party.

So my question is can CometD integration/application works WITHOUT websockets for the above functionality?

When i read their documentation they are always saying, it works over HTTP or Websocket but i could not conclude that whether i can use only HTTP for pushing messages by using CometD integration.

My confusion here is if i integrate the cometD into the existing Spring boot microservice application

  1. Can the CometD provides push mechanism with HTTP only and establish a connection with Server? OR it needs Websockets (ws://) and websocket needs to be enabled in Zuul proxy and web server consecutively to establish a connection with server from browser/UI?
  2. Does it change the complete nature of the existing spring boot restful micro-service to web application

Please guide me on this so that i can proceed further.

Upvotes: 0

Views: 495

Answers (1)

sbordet
sbordet

Reputation: 18507

CometD works perfectly fine without WebSocket, so you can use HTTP to push messages from the CometD server to your browser clients.

From the CometD documentation preface:

CometD provides you APIs to implement these messaging patterns: publish/subscribe, peer-to-peer (via a server), and remote procedure call. This is achieved using a transport-independent protocol, the Bayeux protocol, that can be carried over HTTP or over WebSocket (or other transport protocols), so that your application is not bound to a specific transport technology.

You can disable the WebSocket transport on the server side (see the allowedTransports parameter in this section):

<web-app ...>
  ...
  <servlet>
    <servlet-name>cometd</servlet-name>
    <servlet-class>org.cometd.server.CometDServlet</servlet-class>
    <init-param>
      <param-name>allowedTransports</param-name>
      <param-value>long-polling</param-value>
    </init-param>
    ...
  </servlet>
  ...
</web-app>

For further customization, where you can specify the transport implementation class to use, see also this section.

Upvotes: 1

Related Questions