I'm writing a bridge application in SpringBoot two bridge an internal messaging protocol over to a websocket based stomp setup. I'm operating in a mixed-mode Kotlin
, java
project (which "might" be making things difficult).
My goal is when I receive a message on our internal messaging queue, i wanted to send it over to the STOMP endpoints.
I can send from STOMP->STOMP
and REST->STOMP
but I seem unable to make the server send directly to a stomp endpoint correclty.
I've gone through just about every single stack post - and I see people have had similar issues, yet, I'm unable to actually get any of the listed solutions working.
From what I gather I need to add:
java
@Autowired
private SimpMessagingTemplate template;
kotlin
@Autowired
lateinit var template: SimpleMessagingTemplate
into one of my classes and either add @Controller
or @Service
to the top of the class, possibly making it open
in kotlin
Attempts (java):
@Controller
public class STOMPDataListener implements SDDFDataListener {
@Autowired
private SimpMessagingTemplate template;
public void handleData(String source, SDDFCommonData data) {
System.out.println("Received: " + data);
}
}
If I add a breakpoint on my handleData
call I find out that:
template = null
Attempt (kotlin)
@Controller
class BridgeDataListener(val peerID: String = "default") : SDDFDataListener {
@Autowired
lateinit var template: SimpMessagingTemplate
override fun handleData(source: String, data: SDDFCommonData) {
println("Received: $data")
}
}
If I mark it as
@Service
class BridgeDataListener(val peerID: String = "default") : SDDFDataListener {
I get the same error.
I know this is possible because in the Docs: https://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/html/websocket.html they give an example, however, I'm not sure how I could use this example directly because I need to construct multiple versions of my DataListeners - and from what I understand an @Autowired class you get one copy of only? Could I make it a singleton or would that break something?
@Controller
public class GreetingController {
private SimpMessagingTemplate template;
@Autowired
public GreetingController(SimpMessagingTemplate template) {
this.template = template;
}
@RequestMapping(value="/greetings", method=POST)
public void greet(String greeting) {
String text = "[" + getTimestamp() + "]:" + greeting;
this.template.convertAndSend("/topic/greetings", text);
}
}
Assistance is greatly appreciated.