gpt4 book ai didi

java - 如何使用 Spring Integration 发送 gcm xmpp 消息?

转载 作者:行者123 更新时间:2023-11-30 07:29:25 24 4
gpt4 key购买 nike

我是 Spring Integration 和 Google Cloud Message 的新手。 XmppConnectionFactoryBean 已成功创建,我可以在我的服务类中 Autowiring XmppConnection

@Configuration
class XmppConfig {

@Value("${gcm.sender_id}")
private String senderId;

@Value("${gcm.api_key}")
private String apiKey;

@Value("${gcm.host}")
private String host;

@Value("${gcm.port}")
private int port;

@Bean
public ConnectionConfiguration connectionConfiguration() {
ConnectionConfiguration connectionConfig = new ConnectionConfiguration(host, port);
connectionConfig.setSecurityMode(SecurityMode.enabled);
connectionConfig.setReconnectionAllowed(true);
connectionConfig.setRosterLoadedAtLogin(false);
connectionConfig.setSendPresence(false);
connectionConfig.setSocketFactory(SSLSocketFactory.getDefault());

return connectionConfig;
}

@Bean
public XmppConnectionFactoryBean xmppConnectionFactoryBean() {
XmppConnectionFactoryBean connectionFactoryBean = new XmppConnectionFactoryBean();
connectionFactoryBean.setUser(senderId);
connectionFactoryBean.setPassword(apiKey);
connectionFactoryBean.setConnectionConfiguration(connectionConfiguration());
return connectionFactoryBean;
}

}

服务等级:

class MyServiceImpl implements MyService {

@Autowired
private XmppConnection xmppConnection;

}

这是正确的方法吗?如何向 GCM 发送 XMPP 消息?我应该直接使用 XmppConnection 还是一些 Spring 消息传递抽象?

更新

创建了 MessageHandler 并定义了 bean 名称。

@Bean(name = "xmppConnection")
public XmppConnectionFactoryBean xmppConnectionFactoryBean() {
XmppConnectionFactoryBean connectionFactoryBean = new XmppConnectionFactoryBean();
connectionFactoryBean.setUser(senderId);
connectionFactoryBean.setPassword(apiKey);
connectionFactoryBean.setConnectionConfiguration(connectionConfiguration());
return connectionFactoryBean;
}

@Bean(name = "gcmChannel")
public MessageChannel messageChannel() {
return new DirectChannel();
}

@Bean
@ServiceActivator(inputChannel = "gcmChannel")
public MessageHandler messageHandler() {
return new ChatMessageSendingMessageHandler();
}

@Autowired
@Qualifier("gcmChannel")
private MessageChannel messageChannel;

最佳答案

当然,最好使用特定的 Spring Integration Adapter。它是ChatMessageSendingMessageHandler

我们现在正处于对该适配器的扩展支持的合并阶段:https://github.com/spring-projects/spring-integration/pull/1745 。因此,在下一个 Spring Integration 4.3 版本中,您将获得更多 GCM 支持。

现在,作为解决方法,您必须手动创建带有 GCM 扩展的 XMPP 消息,并将其发送到该 ChatMessageSendingMessageHandler 的 channel 。

关于java - 如何使用 Spring Integration 发送 gcm xmpp 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36361610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com