After starting the pubsub emulator, I'm trying to create a topic and a subscription using the HTTP API. Creating a topic succeeds, but I cannot figure out why creating a subscription doesn't. Am I doing something wrong or is this a bug in the tool? You can see the logs below:
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/topics/mytopic
{
"name": "projects/myproject/topics/mytopic"
}
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/subscriptions/mysub \
--data '{"topic":"projects/myproject/topics/mytopic"}'
Not Found
On the emulator side, I see the following:
# create topic logs
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:19 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected HTTP/2 connection.
# create subscription logs
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Apr 29, 2020 10:37:27 AM io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFO: Unknown request URI: /v1/projects/myproject/subscriptions/mysub
Even though creating a topic works with the above command (no content type necessary), in order to send data with the --data '...'
option, you also need to send the content type header. So the following command does work:
$ curl -s -X PUT http://localhost:8085/v1/projects/myproject/subscriptions/mysub \
-H 'content-type: application/json' \
--data '{"topic":"projects/myproject/topics/mytopic"}'