Firebase上游云消息 [英] Firebase upstream cloud messages
问题描述
我使用这个nodeJS 软件包建立了XMPP服务器。我可以发送一个下游消息(从XMPP服务器到设备),但是当我尝试发送上游消息时,服务器很少收到它。
处理上游消息的服务器上的代码是:
xcs.on('message',function(messageId,from,data,category){
console.log(Got msg)
console.log(arguments)
});
在android studio中,我使用以下方式发送上游消息:
public void send(ArrayList< String> messages){
System.out.println(Attempting to send);
FirebaseMessaging fm = FirebaseMessaging.getInstance();
System.out.println(msgId:+ msgId.get());
RemoteMessage.Builder rm = new RemoteMessage.Builder(SENDER_ID +@ gcm.googleapis.com)
.setMessageId(Integer.toString(msgId.incrementAndGet())); (int i = 0; i< messages.size(); i ++){
rm.addData(String.valueOf(i),messages.get(i));
}
fm.send(rm.build());
$ b 使用print语句我发现send函数确实得到被调用,当我发送时没有错误,但节点服务器什么也没收到。我会注意到服务器SOMETIMES接收到上游消息,但它曾经接近50次尝试。
以下是我从服务器接收到消息后获得的一些调试器输出,然后尝试发回上游消息:
V / FA:会话已开始,时间:3115366
I / FA:找不到标签管理器,因此不会使用
D / FA:记录事件(FE):_s,Bundle [{_ o = auto,_sc = MainActivity,_si = 8922817241262257215}]
V / FA:使用测量服务
V / FA:连接远程服务
D / FA:连接到远程服务
V / FA:处理排队服务任务:1
V / FA:不活动,断开与服务的连接
I / System.out:收到的消息:
I / System.out:Key = TYPE,Value = TEXT
I / System.out:Key = ACTION,Value = GET
I / System.out:试图发送
我不知道问题出在android客户端还是节点服务器上。感谢您的帮助。
解决方案问题在于我使用AWS Lambda托管XMPP服务器,认为我可以将其转换只有当我需要它时。 XMPP服务器需要处于服务器设置(它可以保持开启状态),而不是关闭和打开。细节超越了我。
I've set up an XMPP server using this nodeJS package. I can send a downstream message (from XMPP server to device) just fine, but when I try to send an upstream message the server rarely ever receives it.
The code on the server that handles upstream messages is:
xcs.on('message', function(messageId, from, data, category) {
console.log("Got msg")
console.log(arguments)
});
In android studio I send an upstream message using:
public void send(ArrayList<String> messages) {
System.out.println("Attempting to send");
FirebaseMessaging fm = FirebaseMessaging.getInstance();
System.out.println("msgId: " + msgId.get());
RemoteMessage.Builder rm = new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com")
.setMessageId(Integer.toString(msgId.incrementAndGet()));
for (int i = 0; i < messages.size(); i++) {
rm.addData(String.valueOf(i), messages.get(i));
}
fm.send(rm.build());
}
Using print statements I see that the send function does indeed get invoked and there are no errors when I send but the node server receives nothing. I'll note that the server SOMETIMES receives the upstream messages but its once in nearly 50 tries.
Here's some debugger output that I get when I receive a message from the server then attempt to send back an upstream message:
V/FA: Session started, time: 3115366
I/FA: Tag Manager is not found and thus will not be used
D/FA: Logging event (FE): _s, Bundle[{_o=auto, _sc=MainActivity, _si=8922817241262257215}]
V/FA: Using measurement service
V/FA: Connecting to remote service
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 1
V/FA: Inactivity, disconnecting from the service
I/System.out: Receieved message:
I/System.out: Key = TYPE, Value = TEXT
I/System.out: Key = ACTION, Value = GET
I/System.out: Attempting to send
I don't know whether the problem is with the android client or the node server. Thanks for any help.
解决方案 The issue was that I was using AWS Lambda to host the XMPP server thinking that I could turn it only when I need it. The XMPP server needs to be in a server setting (where it can stay on) rather than turned off and on. Details are beyond me.
这篇关于Firebase上游云消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!