【Azure 事件中心】Spring Boot 集成 Event Hub(azure-spring-cloud-stream-binder-eventhubs)指定Partition Key有异常消息
问题描述
在Spring Boot应用中集成Event Hub,发送消息时指定Partition Key,日志中发现异常:
应用使用Event Hub版本为
<dependency> <groupId>com.azure.spring</groupId> <artifactId>azure-spring-cloud-stream-binder-eventhubs</artifactId> <version>2.5.0</version> </dependency>
发送消息指定Partition Key
@RestController public class ReactiveEventProducerController { private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveEventProducerController.class); @Autowired private Sinks.Many<Message<String>> many; @PostMapping("/messages/reactive") public ResponseEntity<String> reactiveSendMessage(@RequestParam String message) { LOGGER.info("Reactive method to send message: {} to destination.", message); many.emitNext(MessageBuilder.withPayload(message).setHeaderIfAbsent(EventHubHeaders.PARTITION_KEY, String.valueOf(vin.hashCode())).build(), Sinks.EmitFailureHandler.FAIL_FAST); return ResponseEntity.ok(message); } @GetMapping("/") public String welcome() { return "welcome"; } }
异常消息
{"@timestamp":"2022-04-05 13:15:08.643","level":"WARN","host":"bogon","APP":"myehapp","microservice":"ehcenter",
"class":"com.azure.spring.integration.eventhub.converter.EventHubMessageConverter","trackingID":"","spanID":"",
"data":"System property azure_partition_key(1916947495) is not allowed to be defined and will be ignored.","xcptn":""}
问题解答
经过多次测试验证,这个异常消息只是一个Warning(警告),并不影响真正消息的发送。 可以使用Service Bus Explorer( https://github.com/paolosalvatori/ServiceBusExplorer )工具进行查看发送端发送的消息。此外,在消费数据的时候,加上EventHubHeaders.RAW_PARTITION_ID 就可以查看分区情况。
message.getHeaders().get(EventHubHeaders.RAW_PARTITION_ID))
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
分类:
【Azure 事件中心】
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?