I'm trying to send messages to my topic, but the problem is when I send the message nothing happens... I'm using apache tomcat 7.0.53
UPDATE: 04/15: Link to test:
http://ec2-54-187-72-145.us-west-2.compute.amazonaws.com:8080/kupo
Login: admin
Password: admin
LINK TO ACCESS TOMCAT LOG:
http://ec2-54-187-72-145.us-west-2.compute.amazonaws.com:28778/
P.S: You need to checked the combobox on the sidebar to start watch the messages
Github Link: https://github.com/tiarebalbi/kupo
LOG:
DEBUG - gWebSocketHandlerDecorator - Connection established, SockJS session id=_mqg8qer, uri=/kupo/application/807/_mqg8qer/websocket
DEBUG - StompDecoder - Decoded [Payload byte[0]][Headers= {stompCommand=CONNECT, nativeHeaders={heart-beat=[10000,10000], accept-version=[1.1,1.0]}, simpMessageType=CONNECT, id=e79a615e-5522-a0f9-aecf-6ea5a54b3d9b, timestamp=1397013491497}]
DEBUG - StompEncoder - Encoded STOMP command=CONNECTED headers={user-name=[balbi], heart-beat=[0,0], version=[1.1]}
DEBUG - StompDecoder - Decoded [Payload byte[0]][Headers={stompCommand=SUBSCRIBE, nativeHeaders={id=[sub-0], destination=[/topic/greetings]}, simpMessageType=SUBSCRIBE, simpSubscriptionId=sub-0, simpDestination=/topic/greetings, id=42c2019d-96a0-95f0-29aa-2bcc62d6d721, timestamp=1397013491501}]
CODE:
@Service
public class ExampleServiceImpl implements ApplicationListener<BrokerAvailabilityEvent> {
private AtomicBoolean brokerAvailable = new AtomicBoolean();
@Autowired
private MessageSendingOperations<String> messagingTemplate;
@Override
public void onApplicationEvent(BrokerAvailabilityEvent event) {
this.brokerAvailable.set(event.isBrokerAvailable());
}
@Scheduled(fixedDelay=3000)
public void testing() {
if (this.brokerAvailable.get()) {
this.messagingTemplate.convertAndSend("/topic/greetings", "Testing....");
}
}
Javascript Connect:
var socket = new SockJS('/kupo/application'); // <!-- My endpoint
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
var username = frame.headers['user-name'];
console.log("User connected: " + username);
stompClient.subscribe("/topic/greetings", function(message) { // <-- Topic where I want to received the message
console.log("TOPIC:",message);
});
} , function(error) {
console.log("STOMP protocol error " + error);
});
Browser Console:
Opening Web Socket... stomp.min.js:8
Web Socket Opened... stomp.min.js:8
>>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000
<<< CONNECTED
user-name:balbi
heart-beat:0,0
version:1.1
connected to server undefined stomp.min.js:8
User connected: balbi
>>> SUBSCRIBE
id:sub-0
destination:/topic/greetings
Websocket Context Configuration:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketApplicationContext extends AbstractWebSocketMessageBrokerConfigurer {
@Autowired
private Environment env;
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
if (env.acceptsProfiles("test.tomcat")) {
registry.addEndpoint("/application")
.setHandshakeHandler(
new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy()))
.withSockJS();
} else {
registry.addEndpoint("/application").withSockJS();
}
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/");
registry.setApplicationDestinationPrefixes("/app");
}
}