deltio icon indicating copy to clipboard operation
deltio copied to clipboard

Creating topics/subscriptions via docker compose

Open freeleyjenny opened this issue 1 year ago • 5 comments

Hi, We are hoping to move to using this docker image for our pubsub emulator but we have a requirement to do the creation via our docker compose file. With the previous image we were using we were creating the topics and subscriptions via curl command according to the gcloud pubsub api as follows: curl -v -s -X PUT pubsub:8085/v1/settlement-topic curl -v -s -X PUT pubsub:8085/v1/testproject/settlement-project/subscriptions/settlement-subscription
-H 'content-type: application/json'
--data '{"topic":"projects/testproject/topics/settlement-topic"}'

These requests do not seem to be working with this image. Could you please advise if there are changes required to the requests or if it is possible to setup the pubsub emulator in this way with this image?

freeleyjenny avatar Jun 13 '24 23:06 freeleyjenny

Deltio currently doesn’t expose an HTTP-based API (only gRPC).

I wonder if the gcloud CLI uses gRPC, in which case you could use that. You could probably also write a Python or NodeJS script that uses the official PubSub library.

jeffijoe avatar Jun 14 '24 00:06 jeffijoe

Thank you for the quick response, we will try to use grpcurl requests instead. Am I correct in thinking that Deltio does not support project creation at the moment? What is the default project that is created when the container is spun up?

freeleyjenny avatar Jun 14 '24 01:06 freeleyjenny

Any project ID can be used, similar to the official emulator.

jeffijoe avatar Jun 14 '24 08:06 jeffijoe

Hi,

We have been able to successfully create topics and subscriptions via grpcurl thank you for the help. We are however seeing some unusual behaviour around the response of the emulator when we use a context with timeout or context with cancel when subscribing/receiving and there are no events on the subscription. When we used a different pubsub emulator image in the example below we received a timeout if there were no events on the subscription whereas the deltio image seems to not respond or time out as expected. Under the hood cloudeventsConnector uses a google cloudevents client StartReceiver() function. Do you know how this emulator handles context that times out or is cancelled?

ctx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Second)
ctx = subscriberContext.WithLogger(ctx, zap.NewNop().Sugar())

log.Print("Clearing old events")
defer cancelFunc()
var wg sync.WaitGroup
wg.Add(2)
go func() {
    defer wg.Done()
    err := runner.cloudEventsConnector.Subscribe(ctx, func(ctx context.Context, event event.Event) protocol.Result {
	return nil
    })
    if err != nil {
	log.Fatal("ClearEvents failed", err)
    }
}()

freeleyjenny avatar Jun 19 '24 05:06 freeleyjenny

Some questions:

  1. Do you only receive a timeout if the subscription stops producing messages within 5 seconds, or is it 5 seconds after you started subscribing regardless of whether messages are still being produced?
  2. Can you create a minimal reproduction of this using just the PubSub gRPC client?
  3. What timeout behavior are you expecting? Should the subscription call end without an error, or should it return a CANCELLED status?

We're consuming Deltio via a .NET client and cancellation works fine there.

jeffijoe avatar Jun 19 '24 09:06 jeffijoe