问题描述

在Spring Boot应用中集成Event Hub,发送消息时指定Partition Key,日志中发现异常:

应用使用Event Hub版本为

com.azure.spring

azure-spring-cloud-stream-binder-eventhubs

2.5.0

发送消息指定Partition Key

@RestController

public class ReactiveEventProducerController {

private static final Logger LOGGER = LoggerFactory.getLogger(ReactiveEventProducerController.class);

@Autowired

private Sinks.Many> many;

@PostMapping("/messages/reactive")

public ResponseEntity 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))

 

相关文章

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。