0

I'm a newbie in Spring framework. I already have a Spring service which sends some requests to /topic/liveFeed. Here is the code for the existing service I have

public class DataPublisher {

  @Autowired private SimpMessagingTemplate webSocket;

  @Scheduled(fixedRate = 1000)
  public void publish() throws Exception {

    ...

  webSocket.convertAndSend("/topic/liveFeed", currentTick);
  }
}

and in my app.js I have

function connect() {
  var socket = new SockJS('/stocks');
  stompClient = Stomp.over(socket);
  stompClient.connect({}, function (frame) {
  setConnected(true);
  console.log('Connected: ' + frame);
  stompClient.subscribe('/topic/liveFeed', function (tick) {
  console.log(tick)
});
});
}

So, it looks like this service is sending requests to /topic/liveFeed, so I need to create another service which listens to /topic/liveFeed and process the requests. Can someone help where should I start and what other components I need?

HHH
  • 6,085
  • 20
  • 92
  • 164
  • https://spring.io/guides/gs/rest-service/ – Software Engineer Mar 23 '20 at 14:53
  • Your client subscribes to the service and therefore should receive the messages in its callback (where you can process them). You should see the your `console.log` message. What is the relation to the spring service you now want to add? – second Mar 23 '20 at 14:58
  • That's right, I can see the messages in the console. How can I process them? – HHH Mar 23 '20 at 15:00
  • Looks like your using stompJS, check this [example](https://stomp-js.github.io/api-docs/latest/classes/Client.html#subscribe). Then you have a method that receives your message. Now do whatever you want with it :) – second Mar 23 '20 at 15:03
  • I'm not familiar with Spring and its terminology. Do you mind writing some some code in an answers and guide me what other functions/services/classes I need to add? – HHH Mar 23 '20 at 15:05
  • Sorry, but your client seems to be in javascript (which is not spring). I am still not sure what exaclty you are looking for or what it is you are trying to do. – second Mar 23 '20 at 15:06
  • I need to write a Java code which receives the messages (which my client sends) and process them. This piece should be written in Java – HHH Mar 23 '20 at 15:09
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/210171/discussion-between-second-and-hhh). – second Mar 23 '20 at 15:10

0 Answers0