loading...

November 2, 2018

wamp2spring – WAMP Router with Topics and Procedures

wamp2spring serves as a WAMP router and could register remote procedures and publish on topics.wamp2spring offers the option to serve as Web Application Messaging Protocol (WAMP) router publishing on topics and registering remote procedures. The article wamp2spring – Router for WAMP has already described how to set up a router with wamp2spring. In this article, we would learn how the router could publish on topics and register remote procedures.

Understanding RPC and Pub/Sub might be quite helpful for creating microservices communicating via WAMP. The different ways of communicating via the protocol are described in the article Web Application Messaging Protocol.

Register Remote Procedures

After setting up a wamp2spring router as described, you just have to add the annotation @WampProcedure("procedure_name") to the method you want to register as a remote procedure. The arguments of the method are the arguments of the procedure. The method states what should happen when the procedure is called.

@WampProcedure(procedure_name)
public int procedure(int arg1, int arg2) {
    return arg1 + arg2;
}

Publish on Topics

When publishing on a topic, you have to inject the bean WampPublisher.

@Autowired
private WampPublisher wampPublisher;

Afterwards, publishing could be realised with a simple method call of the instance of WampPublisher: wampPublisher.publishToAll(TOPIC,"Hello Subscriber"). Publishing a topic could be done, for example, in a method.

public void publish() {
    wampPublisher.publishToAll(TOPIC, "Hello Subscriber");
}

By the way, the method where you code your procedures and publications in should be annotated either as @Service or @Controller.

An example of a wamp2spring server could be found on my GitHub page.

Posted in Java, Spring, WAMPTaggs: