問(wèn)題描述
在Spring Boot應(yīng)用中集成Event Hub庄岖,發(fā)送消息時(shí)指定Partition Key肌索,日志中發(fā)現(xiàn)異常:
應(yīng)用使用Event Hub版本為
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-cloud-stream-binder-eventhubs</artifactId>
<version>2.5.0</version>
</dependency>
發(fā)送消息指定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":""}
問(wèn)題解答
經(jīng)過(guò)多次測(cè)試驗(yàn)證,這個(gè)異常消息只是一個(gè)Warning(警告)肢执,并不影響真正消息的發(fā)送贴浙。 可以使用Service Bus Explorer( https://github.com/paolosalvatori/ServiceBusExplorer )工具進(jìn)行查看發(fā)送端發(fā)送的消息。此外铛铁,在消費(fèi)數(shù)據(jù)的時(shí)候隔显,加上EventHubHeaders.RAW_PARTITION_ID 就可以查看分區(qū)情況却妨。
message.getHeaders().get(EventHubHeaders.RAW_PARTITION_ID))
image.png
當(dāng)在復(fù)雜的環(huán)境中面臨問(wèn)題,格物之道需:濁而靜之徐清括眠,安以動(dòng)之徐生彪标。 云中,恰是如此!
標(biāo)簽: 事件中心 Azure Event Hub