支持分布式的callback
项目背景:
之前在某次培训的分享中,谈到rxjava、vertx等开源框架,也了解到callback概念,在分享的中某位童鞋谈到分布式下callback如何处理,说实话在当时的环境能够通过几句话描述callback都比较困难,更何况描述分布式下的callback,所以本文我想通过基于jgroup的方式,更好阐述我的理解如何处理分布式下的callback。
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); } }
相关推荐
ptmagic 2020-10-31
深圳克林斯曼 2020-10-10
互联网架构之路 2020-09-17
憧憬 2020-08-21
zyshappy 2020-08-16
xayddxjsjxywuhui 2020-07-20
枫叶上的雨露 2020-07-04
middleware0 2020-06-27
xayddxjsjxywuhui 2020-06-02
joynet00 2020-05-30
molong0 2020-05-17
middleware0 2020-05-17
憧憬 2020-05-16
亦碎流年 2020-05-04
枫叶上的雨露 2020-04-22
loviezhang 2020-04-17
憧憬 2020-03-27
middleware0 2020-03-05
枫叶上的雨露 2020-02-25