Support distributed callback

Background of the project:

       In a previous training sharing, I talked about open source frameworks such as rxjava and vertx, and I also learned about the concept of callback. In the sharing, a certain children's shoes talked about how to handle callbacks in a distributed environment. To be honest, I could pass a few sentences in the environment at that time. It is difficult to describe callbacks in words, let alone describe distributed callbacks, so in this article, I want to better explain my understanding of how to deal with distributed callbacks through a jgroup-based approach.

 

 

 



 

 

public class ReplyingCallback implements CommandCallback<Object, Object> {

    private final JChannel channel;
    private final Serializer serializer;

    private static final Logger logger = LoggerFactory.getLogger(ReplyingCallback.class);
    private final Address address;

    public ReplyingCallback(JChannel channel, Address address, Serializer serializer) {
        this.address = address;
        this.channel = channel;
        this.serializer = serializer;
    }

    @Override
    public void onSend(CommandMessage<?> commandMessage, Object result) {
        try {
            channel.send(address, new ReplyMessage(commandMessage.getIdentifier(),
                                                   result,
                                                   null, serializer));
        } catch (Exception e) {
            logger.error("Unable to send reply to command [name: {}, id: {}]. ",
                         commandMessage.getCommandName(), commandMessage.getIdentifier(), e);
            throw new CommandResponseProcessingFailedException(String.format(
                    "An error occurred while attempting to process command response of type : %s, Exception Message: %s",
                    result.getClass().getName(), e.getMessage()), e);
        }
    }

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326769661&siteId=291194637