reactiveListener
reactiveListener is Objective Queue Subscriber.
Usage
initialize and subscribe
you can use ReactiveListener
like below.
// initialize object with hostname.
ReactiveListener reactiveListener = new ReactiveListener("localhost");
// set queuename you want to subscribe
reactiveListener.setQueue("messageQueue");
// setCallBackClass which implements `ListenerInterface` interface
reactiveListener.setCallBackMethod(test);
// subscribe start
reactiveListener.listen();
set callback action
you should create class which implements ListenerInterface to set callback method.
public class Test implements ListenerInterface {
private String name;
Test(String name){
this.name = name;
}
// callback method that is called when subsribing a message.
@Override
public void callBack(Message message) {
System.out.println("receiveMessage::"+message.toString());
}
// callback method that is called when error happend by subscribing.
@Override
public void errorCallBack(Throwable throwable) {
System.out.println("error::"+throwable.getMessage());
}
}
stop
you can stop subscribing by calling stop() method.
reactiveListener.stop();
messageConverter
setting messageConverter like below.
// set messageConverter
reactiveListener.setMessageConverter(messageConverter);
// default messageConverter is this .
private Jackson2JsonMessageConverter defaultMessageConverter(){
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new JavaTimeModule())
.dateFormat(new StdDateFormat())
.build();
Jackson2JsonMessageConverter jackson2JsonMessageConverter
= new Jackson2JsonMessageConverter(objectMapper);
return jackson2JsonMessageConverter;
}