Use Google Cloud PubSub emulator from Java -


i've setup pubsub.builder root url pointed local pubsub emulator (localhost:8036 @ case). seems working, see emulator receiving test pushes, gives me error 400 bad request.

publish code:

auth = googlecredential.getapplicationdefault(http_transport, json_factory)          .createscoped(pubsubscopes.all()); client = new pubsub.builder(http_transport, json_factory, auth)          .setapplicationname "test"          .setrooturl("http://localhost:8036/")          .build(); msg = new pubsubmessage().encodedata("{\"a\": 1, \"b\": 2}".getbytes()); req = new publishrequest().setmessages(arrays.aslist(msg)); client.projects()   .topics()   .publish("projects/gcloud-default-project/topics/test-topic", req)   .execute(); 

in emulator console output see following (that's basic publishrequest):

[pubsub] jan 27, 2016 9:03:20 pm com.google.cloud.pubsub.testing.v1.fakepubsubgrpcserver$2 operationcomplete [pubsub] info: adding handler(s) newly registered channel. [pubsub] jan 27, 2016 9:03:20 pm com.google.cloud.pubsub.testing.v1.nettyutil$httpversiondecider channelread [pubsub] info: detected non-http/2 connection. [pubsub] jan 27, 2016 9:03:20 pm com.google.cloud.pubsub.testing.v1.nettyutil$httpjsonadapter channelread [pubsub] info: invalid input: expect message object got: "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�v�m-.nlo-v���vji" [pubsub] com.google.protobuf.invalidprotocolbufferexception: expect message object got: "\u001f�\b\u0000\u0000\u0000\u0000\u0000\u0000\u0000�v�m-.nlo-v���vji" [pubsub]    @ com.google.protobuf.util.jsonformat$parserimpl.mergemessage(jsonformat.java:1099) [pubsub]    @ com.google.protobuf.util.jsonformat$parserimpl.merge(jsonformat.java:1075) [pubsub]    @ com.google.protobuf.util.jsonformat$parserimpl.merge(jsonformat.java:973) [pubsub]    @ com.google.protobuf.util.jsonformat$parser.merge(jsonformat.java:201) [pubsub]    @ com.google.cloud.pubsub.testing.v1.pubsubjsongrpcadapters$publisheradapter.handlerequest(pubsubjsongrpcadapters.java:231) [pubsub]    @ com.google.cloud.pubsub.testing.v1.nettyutil$httpjsonadapter.channelread(nettyutil.java:94) [pubsub]    @ io.netty.channel.channelhandlerinvokerutil.invokechannelreadnow(channelhandlerinvokerutil.java:83) 

seems default pubsub client uses different protocol, don't see way configure it.

how can use com.google.apis:google-api-services-pubsub library local emulator?

the emulator not require or handle authentication or authorization; i'm guessing that's problem lies. can try passing null last parameter builder?

also, appears gzip compression must explicitly disabled. please set on builder:

.setgoogleclientrequestinitializer(new googleclientrequestinitializer() {   @override   public void initialize(abstractgoogleclientrequest<?> request) throws ioexception {     request.setdisablegzipcontent(true);   } }) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -