amit srivastava
amit srivastava

Reputation: 743

How to receive a message via Push in Cloud Pub/Sub using Java

I am trying to implement Google Cloud Pub/Sub to receive a message(via Push) using Java but I couldn't find documentation for Java.

I am able to receive message via pull, also any leads to setup and test Endpoint locally would be very helpful.

I have verified and added domain as Endpoint wondering what to do next to start receiving message at that endpoint.

Upvotes: 3

Views: 2998

Answers (2)

Daniel Collins
Daniel Collins

Reputation: 812

A push endpoint in any language is simply an HTTP web server that can receive POST requests with a JSON body of the following form:

{
  "message": {
    "attributes": {
      "key": "value"
    },
    "data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
    "messageId": "136969346945"
  },
  "subscription": "projects/myproject/subscriptions/mysubscription"
}

Documentation for registering your push endpoint is here. There are plenty of Java web server options available such as Tomcat and Jetty.

Upvotes: 1

KayKay
KayKay

Reputation: 593

When you say that you were able to receive the message via pull, do you use some kind of scheduler in the Java app. to pull the message from pub/sub periodically?

If you are still looking for the answer, you can find here the way to write a push end point (sample) and a way to invoke the same from local.

Hope this helps.

Upvotes: 0

Related Questions