- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在使用 Spring Integration 4.1.0 SNAPSHOT。
我有这个 MQTT 出站适配器:
<int-mqtt:outbound-channel-adapter
async="true"
async-events="true"
id="mqttOutput"
channel="httpInputChannel"
client-id="#{controller.mqttPublisherConfig.clientID}"
url="#{controller.mqttPublisherConfig.completeURL}"
default-qos="#{controller.mqttPublisherConfig.qosString}"
default-retained="#{controller.mqttPublisherConfig.retainFlag}"
default-topic="#{controller.mqttPublisherConfig.topic}"
/>
现在在我的 Controller (MVC 应用程序)中,我想接收适配器发出的事件。
我正在实现ApplicatinListener:
@Controller
public class ServletController implements ApplicationListener {
public void onApplicationEvent(ApplicationEvent event)
{
//
}
...
}
仍然,我没有从 MQTT 适配器收到任何事件。
不过,实现 in-event:inbound-channel-adapter 是有效的:
<int-event:inbound-channel-adapter channel="eventLogger"
error-channel="eventErrorChannel"
/>
但我真的很想在代码中处理事件!
最佳答案
您的 @Controller
是否与 MQTT 适配器位于同一应用程序上下文中?或者(这是最常见的), Controller 位于 Web(DispatcherServlet
's)上下文中,而其他 bean 位于由 ContextLoaderListener
加载的根应用程序上下文中。
问题是根上下文中的 bean 无法“看到”servlet 上下文中的 bean,并且子上下文中的监听器不会接收根上下文中发布的事件。
您必须颠覆这个可见性问题 - 要么将业务 bean 移动到 Web 上下文中(通常不推荐,但对于小型应用程序来说并不可怕),或者以某种方式将监听器从根上下文连接到 Controller - 也许通过接线它进入 Controller 并让 Controller 在初始化期间将其自身传递给监听器 (afterPropertiesSet()
)。你会遇到一个类困惑(相互依赖),但它应该可以工作。
顺便说一下,ApplicationListener
可以采用泛型,所以
public class MyListener implements ApplicationListener<MqttIntegrationEvent> { ... }
只会获取 MQTT 事件。
编辑:
另一个解决方案是使用事件 channel 适配器并将 outbound-channel-adapter
添加到 Web 上下文(与 Controller 相同的上下文)...
@Controller
...
public void onMqttEvent(MqttIntegrationEvent event) { ... }
<int:outbound-channel-adapter channel="eventLogger"
ref="myController" method="onMqttEvent" />
它将在根上下文中看到 channel 。
请务必将事件适配器配置为仅接收 MqttIntegrationEvent
。
关于java - Spring 从 MQTT 出站 channel 适配器获取事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24864836/
前不久,哔哩哔哩(一般常称为 B 站)发布了一篇文章《2021.07.13 我们是这样崩的》,详细回顾了他们在 2021.07.13 晚上全站崩溃约 3 小时的至暗时刻,以及万分紧张的故障定位与恢复过
想象一下这种情况,周围有一些智能手机和计算机,它们的 WiFi 适配器(无线适配器)打开,但没有必要连接到网络。 有没有办法通过 Linux 机器查看 MAC 地址? 任何见解表示赞赏。 最佳答案 断
我无法创建新的 Window Station 来运行我的应用程序 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { wprintf(L"
在 Conda 环境中安装包后,我想对该包中的代码进行一些更改。 在哪里可以找到包含已安装包的 site-packages 目录? 我有 Anaconda Python 2.7 base 发行版,但找
今天去改了matplotlib的配置。搜索 matplotlibrc 发现我有两个: 查看site-packages 文件夹,我发现很多包的名称中都有波浪号: ~klearn 是 sklearn ,但
我是一名优秀的程序员,十分优秀!