3

我没有收到来自 Google Play 商店的实时开发者通知。我已按照以下步骤操作:

  1. 设置GOOGLE_APPLICATION_CREDENTIALS

  2. 设置消息侦听器。消息接收者代码

    public List<ReceivedMessage> recieveAndroidNotification() throws IOException {
    
        String subscriptionId = "my-project-id";
        String projectId = "my-subscription-id";
        SubscriberStubSettings subscriberStubSettings = SubscriberStubSettings.newBuilder().build();
        try (SubscriberStub subscriber = GrpcSubscriberStub.create(subscriberStubSettings)) {
            // String projectId = "my-project-id";
            // String subscriptionId = "my-subscription-id";
            int numOfMessages = 10; // max number of messages to be pulled
            String subscriptionName = ProjectSubscriptionName.format(projectId, subscriptionId);
            PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(numOfMessages).setReturnImmediately(false) // return immediately if messages are not available
                    .setSubscription(subscriptionName).build();
    
            // use pullCallable().futureCall to asynchronously perform this operation
            PullResponse pullResponse = subscriber.pullCallable().call(pullRequest);
            List<String> ackIds = new ArrayList<>();
            for (ReceivedMessage message : pullResponse.getReceivedMessagesList()) {
                // handle received message
                // ...
                System.out.println("Message Recived");
                ackIds.add(message.getAckId());
            }
            // acknowledge received messages
            AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder().setSubscription(subscriptionName).addAllAckIds(ackIds)
                    .build();
            // use acknowledgeCallable().futureCall to asynchronously perform this operation
            subscriber.acknowledgeCallable().call(acknowledgeRequest);
            return pullResponse.getReceivedMessagesList();
        }
    }
    
  3. 向 Cloud Pub/Sub 主题发布测试通知,从而在收到实时通知之前验证该主题的设置和配置。(未收到通知)

  4. 手动运行代码然后发送错误:

    WARN [2018-06-06 06:37:02,479] com.google.auth.oauth2.ComputeEngineCredentials:无法检测我们是否在 Google Compute Engine 上运行。

我错过了什么吗?

4

0 回答 0