Class KafkaPublisher
java.lang.Object
org.chenile.pubsub.kafka.impl.KafkaPublisher
- All Implemented Interfaces:
ChenilePub
Kafka-based implementation of the
ChenilePub interface.
Provides methods to publish messages to Kafka topics synchronously or asynchronously.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionKafkaPublisher(org.springframework.kafka.core.KafkaTemplate<String, String> kafkaTemplate, PubSubInfoProvider pubSubInfoProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidPublishes a message asynchronously to the given Kafka topic.private static List<org.apache.kafka.common.header.Header> buildHeaders(String topic, Map<String, Object> properties) Builds Kafka headers from message properties and adds the Chenile topic key.private static IntegergetPartition(Map<String, Object> properties) Extracts the partition number from the properties map.voidPublishes a message to the global Kafka topic.voidpublishToOperation(String service, String operationName, String payload, Map<String, Object> properties) Publishes a message to the given service's operation topic.private static StringsubstituteProperties(String text, Map<String, Object> properties) Replaces placeholders in a string with values from the given properties map.
-
Field Details
-
kafkaTemplate
-
pubSubInfoProvider
-
-
Constructor Details
-
KafkaPublisher
@Autowired public KafkaPublisher(org.springframework.kafka.core.KafkaTemplate<String, String> kafkaTemplate, PubSubInfoProvider pubSubInfoProvider)
-
-
Method Details
-
publishToOperation
public void publishToOperation(String service, String operationName, String payload, Map<String, Object> properties) Publishes a message to the given service's operation topic.- Specified by:
publishToOperationin interfaceChenilePub- Parameters:
service- the service nameoperationName- the operation namepayload- the message payloadproperties- additional message properties
-
asyncPublish
Publishes a message asynchronously to the given Kafka topic.- Specified by:
asyncPublishin interfaceChenilePub- Parameters:
topic- the Kafka topicpayload- the message payloadproperties- additional message properties
-
publish
Publishes a message to the global Kafka topic.- Specified by:
publishin interfaceChenilePub- Parameters:
topic- logical topic name (added as header, not used as Kafka topic)payload- the message payloadproperties- additional message properties
-
buildHeaders
-
substituteProperties
-
getPartition
-