提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.websocket.core.sender.kafka; |
H |
2 |
|
|
3 |
import lombok.RequiredArgsConstructor; |
|
4 |
import org.springframework.amqp.rabbit.annotation.RabbitHandler; |
|
5 |
import org.springframework.kafka.annotation.KafkaListener; |
|
6 |
|
|
7 |
/** |
|
8 |
* {@link KafkaWebSocketMessage} 广播消息的消费者,真正把消息发送出去 |
|
9 |
* |
|
10 |
* @author iailab |
|
11 |
*/ |
|
12 |
@RequiredArgsConstructor |
|
13 |
public class KafkaWebSocketMessageConsumer { |
|
14 |
|
|
15 |
private final KafkaWebSocketMessageSender rabbitMQWebSocketMessageSender; |
|
16 |
|
|
17 |
@RabbitHandler |
|
18 |
@KafkaListener( |
|
19 |
topics = "${iailab.websocket.sender-kafka.topic}", |
|
20 |
// 在 Group 上,使用 UUID 生成其后缀。这样,启动的 Consumer 的 Group 不同,以达到广播消费的目的 |
|
21 |
groupId = "${iailab.websocket.sender-kafka.consumer-group}" + "-" + "#{T(java.util.UUID).randomUUID()}") |
|
22 |
public void onMessage(KafkaWebSocketMessage message) { |
|
23 |
rabbitMQWebSocketMessageSender.send(message.getSessionId(), |
|
24 |
message.getUserType(), message.getUserId(), |
|
25 |
message.getMessageType(), message.getMessageContent()); |
|
26 |
} |
|
27 |
|
|
28 |
} |