FCM XMPP java服务器应用程序

时间:2017-03-09 13:27:54

标签: google-app-engine firebase firebase-cloud-messaging java-server google-app-engine-launch

我想在Google AppEngine上部署FCM XMPP应用。我正在使用这个库https://github.com/thelong1EU/fcmxmppserver,但我在这个后端方面是新手,所以我需要一些帮助。我设法部署它但它没有运行。我不知道如何让AppEngine调用这里的主要功能:

public class EntryPoint {
    public static void main(String[] args) {
        final String fcmProjectSenderId = senderID;
        final String fcmServerKey = key;

        CcsClient ccsClient = CcsClient.prepareClient(fcmProjectSenderId, fcmServerKey, false);

        try {
            ccsClient.connect();
        } catch (XMPPException e) {
            e.printStackTrace();
        }
    }
}

如果我只运行此功能,它一切正常,但部署后它无法启动。我错过了什么?

1 个答案:

答案 0 :(得分:0)

所以我发现了这个:

https://cloud.google.com/appengine/docs/standard/java/an-overview-of-app-engine#scaling_types_and_instance_classes

当app加载时,它会对/_ah/stop执行GET,所以我需要将它添加到我的servlet映射中。我是这样做的:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
    <servlet>
        <servlet-name>Start</servlet-name>
        <servlet-class>eu.long1.jwnotes.fcmserver.StartServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Start</servlet-name>
        <url-pattern>/_ah/start</url-pattern>
        <url-pattern>/_ah/stop</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

在doGet()中我这样做:

public class StartServlet extends HttpServlet {

    private static final String GET_START = "/_ah/start";
    private static final String GET_STOP = "/_ah/stop";

    @Override
    public void init() throws ServletException {
     //init the servlet
    }

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        switch (req.getRequestURI()) {
            case GET_START:
                //do something
                resp.setStatus(SC_OK);
                break;

            case GET_STOP:
                //do something else
                break;
        }
    }
}

我不知道这是否是推荐方式,但现在可以使用。如果我找到别的东西,我会发布。