seti.getUserIds())在 publishMessage 方法上返回空列表。客户端未断开连接,并且未触发seti presenceRemoved。但是,seti.getUserIds())在 listenMetaChannel 中返回正确值的userId列表。在publishMessage方法中,Seti不是Null。 Seti适当地注入了这门课程。
@Singleton
@Named
@Service("notificationService")
public class NotificationService {
@Session
private ServerSession serverSession;
private Logger logger = Logger.getLogger(this.getClass());
@Autowired
private BayeuxServer bayeuxServer;
@Autowired
private Seti seti;
@Configure("/notification")
public void configureChannel(ConfigurableServerChannel channel)
{
channel.setPersistent(true);// channel persistent
channel.addAuthorizer(GrantAuthorizer.GRANT_ALL);
//channel.setLazy(true);
}
public void publishMessage( String messageId ,String userId)
{
logger.debug("Seti Session USERS::"+seti.getUserIds());
String userId="568";
boolean userPresent=seti.isPresent(userId);
if(userPresent){
Map<String, Object> push_data= new HashMap<String, Object>();
push_data.put("messageId", messageId);
seti.sendMessage(userId, "/channel", push_data);
}else
{
logger.debug("User ::"+userId+" Session Absent !! ");
}
}
@Listener(Channel.META_CONNECT)
public void listenMetaChannel(ServerSession remote, ServerMessage message)
{
logger.debug("Seti Session USERS::"+seti.getUserIds());
}
}