NettyConnectedMessageListener cml = new NettyConnectedMessageListener();
cml.setHeartbeatContainer(heartbeatContainer);
cml.setGateway(gateway);
gateway.addMessageListener(cml);
NettyDisconnectListenerAndInterceptor disconnect = new NettyDisconnectListenerAndInterceptor();
disconnect.setCloseOnDisconnectMessage(false);
gateway.addMessageListener(disconnect);
gateway.addOutgoingMessageInterceptor(disconnect);
disconnect.setGateway(gateway);
gateway.setHandler(channelHandler);
return gateway;
}