Cometd Documentation states: A good place in the code to perform subscriptions is in a */meta/handshake function. Since /meta/handshake listener are invoked in both explicit handshakes the client performs and in re-handshakes the server triggers, it is guaranteed that your subscriptions are always performed properly and kept consistent with the server state.* JavaScript and Inherited style doesn't lose subscribers when the the network connection is resumed. Subscribers are lost when using annotated cometd java client for the code as shown below. How do you subscribe to the channel inside bayeuxClient.handshake(); method using annotated style.
Annotated Style
@Service
public class Service
{
@Session
private ClientSession bayeuxClient;
@Listener(Channel.META_CONNECT)
public void metaConnect(Message connect)
{
// Connect handling...
}
@Subscription("/foo")
public void foo(Message message)
{
// Message handling...
}
}
Inherited Style
ClientSession bayeuxClient = ...;
bayeuxClient.getChannel(Channel.META_CONNECT).addListener(new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
// Connect handling...
}
});
bayeuxClient.handshake();
bayeuxClient.waitFor(1000, BayeuxClient.State.CONNECTED);
bayeuxClient.getChannel("/foo").subscribe(new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
// Message handling...
}
});