且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase上游云消息

更新时间:2023-02-26 22:05:57

问题在于我使用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.