UNPKG

@dugongjs/kafkajs

Version:

18 lines (17 loc) 1.08 kB
import * as changeCase from "change-case"; /** * MessageChannelParticipantKafkaJs is an implementation of the IMessageChannelParticipant interface that provides a method to generate message channel IDs for Kafka topics based on the origin and aggregate type. */ export class MessageChannelParticipantKafkaJs { /** * Generates a unique message channel ID based on the provided origin and aggregate type. * @param origin The origin or source of the messages (e.g., service name or application name). * @param aggregateType The type of aggregate or domain entity that the channel is associated with (e.g., "Order", "User", etc.). * @returns A unique message channel ID string in kebab-case format, combining the origin and aggregate type. For example: "my-service-order". */ generateMessageChannelIdForAggregate(origin, aggregateType) { const originKebabCase = changeCase.kebabCase(origin); const aggregateTypeKebabCase = changeCase.kebabCase(aggregateType); return `${originKebabCase}-${aggregateTypeKebabCase}`; } }