Skip to content

Commit

Permalink
Add publish/consume guides into README
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhyeong committed Aug 16, 2024
1 parent ce5aba7 commit 6ccc45b
Showing 1 changed file with 122 additions and 1 deletion.
123 changes: 122 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,130 @@

Event Driven lightweight message format

[Document](https://github.com/naver/eventeria/wiki)
## Version compatibility

eventeria | spring-boot | spring-cloud-stream
-----------|---------------|---------------------
1.2.1 | 3.2.x | 4.1.x
1.1.1 | 3.0.x ~ 3.1.x | 4.0.x
1.0.1 | 2.7.x | 3.2.x

## Getting Started

- [Document](https://github.com/naver/eventeria/wiki)
- [spring-boot-eventeria guide projects](https://github.com/naver/eventeria/tree/main/guide-projects/spring-boot-eventeria-guide)

```gradle
dependencies {
implementation("com.navercorp.eventeria:spring-boot-eventeria:${version}")
}
```

```java
@Configuration
public class MessageConfig {
@Bean
ChannelBindable channelBindable() {
return new ChannelBindable();
}

@Bean
@ConditionalOnMissingBean
ChannelBinder channelBinder(
SubscribableChannelBindingTargetFactory bindingTargetFactory,
ChannelBindable channelBindable
) {
return new DefaultChannelBinder(bindingTargetFactory, channelBindable);
}
}
```

## Produce `Message`s

1. Register your spring-cloud-stream produce channel in application.yml or application.properties
```yml
spring:
cloud:
stream:
bindings:
outbound-kafka-channel-command:
destination: command_topic
producer:
partition-count: 2
```
2. Register beans of outbound `MessageChannel`, `SpringMessagePublisher`, `IntegrationFlow`.
- [example code](https://github.com/naver/eventeria/blob/main/guide-projects/spring-boot-eventeria-guide/src/main/java/com/navercorp/eventeria/guide/boot/publisher/ProgrammaticBindingNotifyCommandPublisher.java)
3. Inject `SpringMessagePublisher` bean and publish messages.

```java
@Service
public class ExampleService {
ExampleService(
@Qualified("springMessagePublisherBean") SpringMessagePublisher springMessagePublisher
) {
this.springMessagePublisher = springMessagePublisher;
}
public void publish(Message message) {
springMessagePublisher.publish(message);
}
}
```

> **NOTE:** Does not support Functional publishing currently.

## Consume `Message`s

1. First, register your spring-cloud-stream consume channel in application.yml or application.properties
```yml
spring:
cloud:
stream:
bindings:
inbound-kafka-channel-command:
group: example_group
destination: command_topic
consumer:
concurrency: 1
```
2. Choose one of the Programmatic or Functional way to consume `Message`s.

### Programmatic way

- Register beans of inbound `SubscribableChannel`, `SpringMessagePublisher`, `IntegrationFlow`. `MessageRouter`
- [example code](https://github.com/naver/eventeria/blob/main/guide-projects/spring-boot-eventeria-guide/src/main/java/com/navercorp/eventeria/guide/boot/listener/ProgrammaticBindingEventListener.java)
- `MessageRouter`: route messages to your application.

### Functional way

1. Register additional function mappings in application.yml or application.properties.
```yml
spring:
cloud:
function:
definition:
transformCloudEventToMessage|consumeImplementsEventeriaMessage;
transformCloudEventToMessage|consumeXXX;
```
2. Register `Function` bean which converts spring-messaging `Message` to eventeria `Message`.
```java
@Bean
Function<org.springframework.messaging.Message<byte[]>, Message> transformCloudEventToMessage(
CloudEventMessageReaderWriter cloudEventMessageReaderWriter
) {
return FunctionalBindingSupports.convertToMessage(cloudEventMessageReaderWriter);
}
```
3. Register your `Consumer` bean which receives data type of eventeria `Message`.
```java
@Bean
Consumer<ImplementsEventeriaMessage> consumeImplementsEventeriaMessage() {
return command -> log.info("[CONSUME][consumeImplementsEventeriaMessage] {}", command);
}
```

## License

```
Copyright (c) 2022-present NAVER Corp.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit 6ccc45b

Please sign in to comment.