Spring 集成@ServiceActivator 或@Bean 定义以支持@Profile 的使用
Spring Integration @ServiceActivator or @Bean definition to support @Profile usage
我对服务激活器的使用和定义方式有疑问
我有 3 个服务激活器,它们从不同的输入通道获取消息并将它们发送到单个输出通道。这是在“开发”环境中设计的...
@ServiceActivator(inputChannel = "irregularMessageChannel_1", outputChannel = "combinedChannel")
public String handlerSite1(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
@ServiceActivator(inputChannel = "irregularMessageChannel_2", outputChannel = "combinedChannel")
public String handlerSite2(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
@ServiceActivator(inputChannel = "irregularMessageChannel_3", outputChannel = "combinedChannel")
public String handlerSite3(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
但是在生产环境或预生产环境中我需要再添加一个...所以我检查了使用@ServiceActivator 的@Profile 注释,如下所示
@ServiceActivator(inputChannel = "irregularMessageChannel_X", outputChannel = "combinedChannel")
@Profile("prod")
public String handlerSiteX(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
但据我所知,@Profile 不能与@ServiceActivator 一起使用,它也需要@Bean 定义。
但是
当我用谷歌搜索时,上面写着如果我使用@Bean 定义,我应该 return MessageHandler...我只是创建 MessageHandler 并 return 它...
@Bean
@ServiceActivator(inputChannel = "irregularMessageChannel_X",outputChannel = "combinedChannel")
@Profile("prod")
public MessageHandler handlerSiteX() {
MessageHandler handler = new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", message.getHeaders().get(IpHeaders.IP_ADDRESS), message);
}
};
return handler ;
}
问题部分 - 1
现在我有疑问,如何将消息发送到输出通道,就像我在@ServiceActivator 中使用的那样?
与@Bean 注释一起,不允许在@ServiceActivator 中使用outputChannel 属性。或者有什么方法可以在没有 @Bean 而使用 @ServiceActivator 的情况下使用 @Profile 注释?
EDIT
问题部分 - 2
我还应该自己创建输入通道吗?如果我使用@Bean 定义还是像@ServiceActivator 那样自动创建?
感谢您的帮助。
您必须赢得客户的信任,这就是为什么您必须利用您的资源来提供出色的定制包装解决方案的原因。 Custom-made 包装解决方案需要指定,因此,您需要使用具有卓越品质的个性化产品包装。
Custom packaging
您只能在 @Bean
上使用 @Profile
,而不能在 @Bean
.
中的 @ServiceActivator
方法上使用
见Annotations on @Bean Methods。
您的 @Bean
应如下所示:
@Bean
@Profile("...")
@ServiceActivator(inputChannel = "...")
public MessageHandler profiledHandler() {
ServiceActivatingHandler handler = new ServiceActivatingHandler(myServiceBean,
"handlerSiteX");
handler.setOutputChannelName("combinedChannel");
return handler;
{
输出通道在处理程序上进行;是的,如果需要,将创建输入通道。
我对服务激活器的使用和定义方式有疑问
我有 3 个服务激活器,它们从不同的输入通道获取消息并将它们发送到单个输出通道。这是在“开发”环境中设计的...
@ServiceActivator(inputChannel = "irregularMessageChannel_1", outputChannel = "combinedChannel")
public String handlerSite1(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
@ServiceActivator(inputChannel = "irregularMessageChannel_2", outputChannel = "combinedChannel")
public String handlerSite2(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
@ServiceActivator(inputChannel = "irregularMessageChannel_3", outputChannel = "combinedChannel")
public String handlerSite3(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
但是在生产环境或预生产环境中我需要再添加一个...所以我检查了使用@ServiceActivator 的@Profile 注释,如下所示
@ServiceActivator(inputChannel = "irregularMessageChannel_X", outputChannel = "combinedChannel")
@Profile("prod")
public String handlerSiteX(String data, @Header(IpHeaders.IP_ADDRESS) String connectionId) {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", connectionId, data);
return data;
}
但据我所知,@Profile 不能与@ServiceActivator 一起使用,它也需要@Bean 定义。
但是
当我用谷歌搜索时,上面写着如果我使用@Bean 定义,我应该 return MessageHandler...我只是创建 MessageHandler 并 return 它...
@Bean
@ServiceActivator(inputChannel = "irregularMessageChannel_X",outputChannel = "combinedChannel")
@Profile("prod")
public MessageHandler handlerSiteX() {
MessageHandler handler = new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
if (log.isDebugEnabled())
log.debug("content received from : {} data : {} ", message.getHeaders().get(IpHeaders.IP_ADDRESS), message);
}
};
return handler ;
}
问题部分 - 1
现在我有疑问,如何将消息发送到输出通道,就像我在@ServiceActivator 中使用的那样?
与@Bean 注释一起,不允许在@ServiceActivator 中使用outputChannel 属性。或者有什么方法可以在没有 @Bean 而使用 @ServiceActivator 的情况下使用 @Profile 注释?
EDIT
问题部分 - 2
我还应该自己创建输入通道吗?如果我使用@Bean 定义还是像@ServiceActivator 那样自动创建?
感谢您的帮助。
您必须赢得客户的信任,这就是为什么您必须利用您的资源来提供出色的定制包装解决方案的原因。 Custom-made 包装解决方案需要指定,因此,您需要使用具有卓越品质的个性化产品包装。 Custom packaging
您只能在 @Bean
上使用 @Profile
,而不能在 @Bean
.
@ServiceActivator
方法上使用
见Annotations on @Bean Methods。
您的 @Bean
应如下所示:
@Bean
@Profile("...")
@ServiceActivator(inputChannel = "...")
public MessageHandler profiledHandler() {
ServiceActivatingHandler handler = new ServiceActivatingHandler(myServiceBean,
"handlerSiteX");
handler.setOutputChannelName("combinedChannel");
return handler;
{
输出通道在处理程序上进行;是的,如果需要,将创建输入通道。