Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the connection associated with an Atmosphere @ManagedService message

In this example, is there a way to modify this method

@org.atmosphere.config.service.Message(encoders = {JacksonEncoder.class}, decoders = {JacksonDecoder.class})
public Message onMessage(Message message) throws IOException {
    logger.info("{} just send {}", message.getAuthor(), message.getMessage());
    return message;
}

so I can get the UUID (available in the AtmosphereResource upon connection) so that I know which connection the message is coming from? I have tried adding an AtmosphereResource parameter, but it doesn't work (no message is received).

like image 315
Steve Avatar asked Dec 04 '25 14:12

Steve


1 Answers

Actually, an AtmosphereResource parameter can be added to onMessage. It must be the first parameter. (I tried to add it as the second parameter and it didn't work.)

So the method in the question can be changed to this:

@org.atmosphere.config.service.Message(encoders = {JacksonEncoder.class}, decoders = {JacksonDecoder.class})
public Message onMessage(AtmosphereResource r, Message message) throws IOException {

    // TODO: Look up any info associated with the connection using r.uuid().

    logger.info("{} just send {}", message.getAuthor(), message.getMessage());
    return message;
}
like image 134
Steve Avatar answered Dec 07 '25 03:12

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!