Skip to content

Commit 146f5a8

Browse files
authored
[chores]: added new @SendTo and @ShortCircuit examples;
1 parent ca000cc commit 146f5a8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ public class MessageService {
6060
}
6161
```
6262

63+
### Compound Operations
64+
```
65+
public class MessageService {
66+
@KafkaListener(topic = "test-topic1", groupId = "test-group")
67+
public void handleMessage1(String message) {
68+
System.out.println("1-🕒 Received at " + System.currentTimeMillis());
69+
System.out.println("1-📥 Message: " + message);
70+
}
71+
72+
@KafkaListener(topic = "test-topic2", groupId = "test-group")
73+
@SendTo(topic = "processed-topic2")
74+
public String handleMessage2(String message) {
75+
System.out.println("2-🕒 Received at " + System.currentTimeMillis());
76+
System.out.println("2-📥 Message: " + message);
77+
// Forward processed message to another topic
78+
return "Processed: " + message;
79+
}
80+
81+
@KafkaListener(topic = "test-topic3", groupId = "test-group")
82+
@ShortCircuit(topic = "error-topic3")
83+
public void handleMessageWithError(String message) {
84+
if (message.contains("fail")) {
85+
throw new RuntimeException("Error detected in message!");
86+
}
87+
System.out.println("3-🕒 Message: " + message);
88+
}
89+
}
90+
```
91+
6392
## 🛠️ Architecture
6493

6594
```

0 commit comments

Comments
 (0)