Skip to content

Commit 1b9ef80

Browse files
committed
sync loopback4-kafka-client docs
1 parent af02787 commit 1b9ef80

File tree

1 file changed

+11
-4
lines changed
  • docs/arc-api-docs/extensions/loopback4-kafka-client

1 file changed

+11
-4
lines changed

docs/arc-api-docs/extensions/loopback4-kafka-client/README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
</a>
2424
</p>
2525

26-
2726
## Overview
2827

2928
A Kafka Client for Loopback4 built on top of [KafkaJS](https://kafka.js.org/).
@@ -97,7 +96,13 @@ export class TestStream implements IStreamDefinition {
9796

9897
### Consumer
9998

100-
A Consumer is a [`loopback extension`](https://loopback.io/doc/en/lb4/Extension-point-and-extensions.html) that is used by the [`KafkaConsumerService`](./src/services/kafka-consumer.service.ts) to initialize consumers. It must implement the `IConsumer` interface and should be using the `@consumer()` decorator. If you want the consumers to start at the start of your application, you should pass the `initObservers` config to the Component configuration.
99+
A Consumer is a [`loopback extension`](https://loopback.io/doc/en/lb4/Extension-point-and-extensions.html) that is used by the [`KafkaConsumerService`](./src/services/kafka-consumer.service.ts) to initialize consumers. It must implement one of the `IConsumer`, `ISharedConsumer` or `IGenericConsumer` interfaces and should be using the `asConsumer` binding template. If you want the consumers to start at the start of your application, you should pass the `initObservers` config to the Component configuration.
100+
101+
- `IConsumer` - simple consumer for 1 event in a stream
102+
- `ISharedConsumer` - consumer that consumes data for multiple events in a stream (defined with an array of events)
103+
- `IGenericConsumer` - consumer that consumes data for all events in a stream/topic (defined without any event). By default it is not triggered for an event if a more specific consumer is bound for that event. This behaviour can be changed using the `alwaysRunGenericConsumer` option in consumer configuration.
104+
105+
You can bind any consumer related configuration using the `KafkaClientBindings.ConsumerConfiguration` key. It accepts all the options of KafkaJS, along with an additional option - `alwaysRunGenericConsumer` - this option runs any generic consumer if available always, even if more specific consumers are bound by the client(only the specific consumer would run if this option is false or not provided).
101106

102107
##### Example
103108

@@ -112,13 +117,14 @@ this.configure(KafkaConnectorComponentBindings.COMPONENT).to({
112117

113118
```ts
114119
// start.consumer.ts
120+
// use @genericConsumer for a generic consumer
115121
@consumer<TestStream, Events.start>()
116122
export class StartConsumer implements IConsumer<TestStream, Events.start> {
117123
constructor(
118124
@inject('test.handler.start')
119125
public handler: StreamHandler<TestStream, Events.start>,
120126
) {}
121-
topic: Topics.First = Topics.First;
127+
topic = Topics.First;
122128
event: Events.start = Events.start;
123129
// you can write the handler as a method
124130
handler(payload: StartEvent) {
@@ -149,7 +155,7 @@ export class StartConsumer implements IConsumer<TestStream, Events.start> {
149155
@eventHandler<TestStream>(Events.Start)
150156
public handler: StreamHandler<TestStream, Events.start>,
151157
) {}
152-
topic: Topics.First = Topics.First;
158+
topic = Topics.First;
153159
event: Events.start = Events.start;
154160
}
155161
```
@@ -158,6 +164,7 @@ export class StartConsumer implements IConsumer<TestStream, Events.start> {
158164

159165
A Producer is a loopback service for producing message for a particular topic, you can inject a producer using the `@producer(TOPIC_NAME)` decorator.
160166
Note: The topic name passed to decorator must be first configured in the Component configuration's topic property -
167+
If you want to produce a raw message without any event type, you can use the `@genericProducer(TOPIC_NAME)` decorator, note that in this case, the topic name must be passed in the genericTopics property of the component configuration.
161168

162169
#### Example
163170

0 commit comments

Comments
 (0)