我正在向 Azure 事件中心发送一条消息,但收到的消息在标头值的开头包含“�$”。代码:
import com.azure.core.credential.TokenCredential;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.messaging.eventhubs.EventData;
import com.azure.messaging.eventhubs.EventDataBatch;
import com.azure.messaging.eventhubs.EventHubClientBuilder;
import com.azure.messaging.eventhubs.EventHubProducerClient;
import com.microsoft.azure.spring.integration.eventhub.converter.EventHubMessageConverter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
newMessageHeaders.put("junk", "mock");
MessageHeaders messageHeaders = new MessageHeaders(newMessageHeaders);
Message<String> message = new Message<String>() {
@Override
public String getPayload() {
return "MockPayload";
}
@Override
public MessageHeaders getHeaders() {
return messageHeaders;
}
};
System.setProperty("AZURE_CLIENT_SECRET", "secret");
System.setProperty("AZURE_CLIENT_ID", "client");
System.setProperty("AZURE_TENANT_ID", "tenant");
TokenCredential credential = new DefaultAzureCredentialBuilder().build();
EventHubProducerClient eventHubProducerClient = new EventHubClientBuilder()
.credential("namespaceName.servicebus.windows.net", "mockTopic", credential)
.buildProducerClient();
EventHubMessageConverter messageConverter= new EventHubMessageConverter();
eventHubProducerClient.getEventHubName();
eventHubProducerClient.getEventHubProperties();
EventData eventData = messageConverter.fromMessage(message,EntryData.class);
EventDataBatch batch = eventHubProducerClient.createBatch();
batch.tryAdd(eventData);
eventHubProducerClient.send(batch);
eventHubProducerClient.close();
在 azure hub 事件中心接收到的消息在标题下接收到的值为“�$mock”