forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
增加 spring cloud stream rabbitmq 示例(消息确认,完成乱炖)
- Loading branch information
YunaiV
committed
Mar 6, 2020
1 parent
8e80452
commit fd39615
Showing
4 changed files
with
54 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...r/springcloud/labx10/rabbitmqdemo/producerdemo/message/Demo01ProducerConfirmCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cn.iocoder.springcloud.labx10.rabbitmqdemo.producerdemo.message; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.integration.annotation.ServiceActivator; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Demo01ProducerConfirmCallback { | ||
|
||
private Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@ServiceActivator(inputChannel = "demo01-producer-confirm") | ||
public void onPublisherConfirm(Message message) { | ||
logger.info("[onPublisherConfirm][headers:{}]", message.getHeaders()); | ||
logger.info("[onPublisherConfirm][payload:{}]", message.getPayload()); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...er/springcloud/labx10/rabbitmqdemo/producerdemo/message/Demo01ProducerReturnCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cn.iocoder.springcloud.labx10.rabbitmqdemo.producerdemo.message; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.cloud.stream.annotation.StreamListener; | ||
import org.springframework.integration.annotation.ServiceActivator; | ||
import org.springframework.integration.context.IntegrationContextUtils; | ||
import org.springframework.messaging.support.ErrorMessage; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Demo01ProducerReturnCallback { | ||
|
||
private Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@ServiceActivator(inputChannel = "DEMO-TOPIC-01.errors") | ||
public void handleError(ErrorMessage errorMessage) { | ||
logger.error("[handleError][headers:{}]", errorMessage.getHeaders()); | ||
logger.error("[handleError][payload:{}]", errorMessage.getPayload().getMessage()); | ||
logger.error("[handleError][originalMessage:{}]", errorMessage.getOriginalMessage()); | ||
} | ||
|
||
@StreamListener(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME) // errorChannel | ||
public void globalHandleError(ErrorMessage errorMessage) { | ||
logger.error("[globalHandleError][payload:{}]", errorMessage.getPayload().getMessage()); | ||
logger.error("[globalHandleError][originalMessage:{}]", errorMessage.getOriginalMessage()); | ||
logger.error("[globalHandleError][headers:{}]", errorMessage.getHeaders()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters