spring-boot - Spring 集成:从消息中删除 Jms 和 Http 标头
问题描述
我有这样的集成流程
订阅者和发布者
Broker->queue1->Transform->HTTP CALL->HTTP Response->JMS Message->Broker->queue2
这是我的集成流 DSL
@Bean
public IntegrationFlow orchestrationFlow() {
return IntegrationFlows.from(Jms.messageDrivenChannelAdapter(connectionFactory).destination("MAILBOX"))
//destination("amq.outbound1"))
.<String, String>transform(s -> {
return s.toLowerCase();
}).log()
.transform(new PojoTransformer())
//.headerFilter("^(jms?|JMS)://.*$", true)
.log()
// HTTP part goes here
.<String, HttpEntity<String>>transform(HttpEntity::new).handle(
Http.outboundGateway("http://localhost:8080/uppsercase").httpMethod(HttpMethod.POST)
.extractPayload(true).expectedResponseType(String.class))
.log()
.headerFilter("(.*?)", true)
.log()
//.<HttpEntity<String>,String>transform(HttpEntity<String>::getBody)
// and here HTTP part ends
.handle(Jms.outboundAdapter(connectionFactory).destination("MAILBOXX")).get();
}
public static class PojoTransformer {
@Transformer
public String transform(@Payload String email, @Headers MessageHeaders headers) {
return email;
}
}
我想在进行 http 调用之前从消息中删除 Jms 标头还想在将 HTTP 标头发送到 JMS 之前删除它
我尝试使用不同的方法 @Transformer
和 headerFilter
但是没有任何作用,由于没有清除标头,因此不需要的标头被发送到 JMS 和 HTTP 请求
我在这里粘贴日志
GenericMessage [payload=something, headers={JMS_IBM_Character_Set=UTF-8, JMS_IBM_MsgType=8, jms_destination=queue:///MAILBOX, JMSXUserID=admin , JMS_IBM_Encoding=273, priority=4, jms_timestamp=1532706892455, JMSXAppID=SpringIntegrationDemoApplica, JMS_IBM_PutApplType=28, JMS_IBM_Format=MQSTR , jms_redelivered=false, JMS_IBM_PutDate=20180727, JMSXDeliveryCount=1, JMS_IBM_PutTime=15545246, id=5f5fe393-42e3-9ab9-3170-739bf7e4f72b, jms_messageId=ID:414d5120514d31202020202020202020872a5b5b02781521, timestamp=1532706892732}]
GenericMessage [payload=something, headers={JMS_IBM_Character_Set=UTF-8, JMS_IBM_MsgType=8, jms_destination=queue:///MAILBOX, JMSXUserID=admin , JMS_IBM_Encoding=273, priority=4, jms_timestamp=1532706892455, JMSXAppID=SpringIntegrationDemoApplica, JMS_IBM_PutApplType=28, JMS_IBM_Format=MQSTR , jms_redelivered=false, JMS_IBM_PutDate=20180727, JMSXDeliveryCount=1, JMS_IBM_PutTime=15545246, id=d81f301b-7033-65be-9dd2-6bda3a200b3a, jms_messageId=ID:414d5120514d31202020202020202020872a5b5b02781521, timestamp=1532706892737}]
GenericMessage [payload=SOMETHING IS CONVERTED TO UPPERCASE, headers={JMS_IBM_Character_Set=UTF-8, JMS_IBM_MsgType=8, jms_destination=queue:///MAILBOX, JMSXUserID=admin , JMS_IBM_Encoding=273, priority=4, jms_timestamp=1532706892455, http_statusCode=201, Date=1532706892000, JMSXAppID=SpringIntegrationDemoApplica, JMS_IBM_PutApplType=28, JMS_IBM_Format=MQSTR , jms_redelivered=false, JMS_IBM_PutDate=20180727, JMSXDeliveryCount=1, JMS_IBM_PutTime=15545246, id=e464d287-b32b-0bdc-e008-c3d5bf70e45a, Content-Length=35, contentType=text/plain;charset=UTF-8, jms_messageId=ID:414d5120514d31202020202020202020872a5b5b02781521, timestamp=1532706892783}]
GenericMessage [payload=SOMETHING IS CONVERTED TO UPPERCASE, headers={JMS_IBM_Character_Set=UTF-8, JMS_IBM_MsgType=8, jms_destination=queue:///MAILBOX, JMSXUserID=admin , JMS_IBM_Encoding=273, priority=4, jms_timestamp=1532706892455, http_statusCode=201, Date=1532706892000, JMSXAppID=SpringIntegrationDemoApplica, JMS_IBM_PutApplType=28, JMS_IBM_Format=MQSTR , jms_redelivered=false, JMS_IBM_PutDate=20180727, JMSXDeliveryCount=1, JMS_IBM_PutTime=15545246, id=e464d287-b32b-0bdc-e008-c3d5bf70e45a, Content-Length=35, contentType=text/plain;charset=UTF-8, jms_messageId=ID:414d5120514d31202020202020202020872a5b5b02781521, timestamp=1532706892783}]
: failed to map Message header 'Content-Length' to JMS property
有人能告诉我为什么我的转换不能正常工作吗
解决方案
您确实需要使用 a .headerFilter()
,但只有它不支持的问题regexp
:
/**
* Removes all headers provided via array of 'headerPatterns'. As the name suggests the array
* may contain simple matching patterns for header names. Supported pattern styles are:
* "xxx*", "*xxx", "*xxx*" and "xxx*yyy".
*
* @param headerPatterns The header patterns.
* @return this.
*/
public abstract AbstractIntegrationMessageBuilder<T> removeHeaders(String... headerPatterns);
推荐阅读
- c++ - 如何使用多态性将相同的操作应用于具有相同基类的不同对象的 unordered_sets?
- windows - 为什么 pyspark 脚本在我的个人计算机上运行而不是在我的工作计算机上运行?
- python - 使用 for 循环注册 python 图形形状时遇到问题
- ruby - Ruby 可以与我的 root 权限交互吗?
- javascript - 将 dataURL 传递给 href 会生成带有文本“未定义”的文件
- excel - 从第三个打开两个单独的 Excel 工作簿
- python - 根据另一个中的匹配对元组列表进行排序
- jquery - jQuery 获取用户的 Skype 联系人
- android-ndk - 使用未声明的标识符“vpaddq_u8”
- gcloud - 错误:(gcloud.firebase.test.android.run)“像素”不是有效模型