Closed wrobell closed 2 years ago
The behavior is by protocol that is different from AMQP.
If you want make it idempotent you have to catch the exception.
We do the same in Java, Go and Rust * EDIT Not true anymore we changed the behaviour.
See: https://github.com/qweeze/rstream/issues/6#issuecomment-944347523
I guess we could add something like exist_ok: bool
parameter to create_stream
and hide exception handling from user to get more friendly api. Pathlib does that
Sounds good to me !
Looking at Java client documentation, it says
StreamCreator#create is idempotent: trying to re-create a stream with the same name and same properties (e.g. maximum size, see below) will not throw an exception. In other words, you can be sure the stream has been created once StreamCreator#create returns. Note it is not possible to create a stream with the same name as an existing stream but with different properties. Such a request will result in an exception.
sorry @wrobell you are right. We updated it recently.
btw the @qweeze's idea looks good to me
I added exist_ok
parameter to create_stream
to both producer and consumer, and also missing_ok
parameter to delete_stream
Speaking of idempotence of stream re-creation - as far as I can see there's currently no way to retrieve existing stream's properties from RabbitMQ. So we only can check if the stream with same name exists, but we cannot check both name and properties.
as far as I can see there's currently no way to retrieve existing stream's properties from RabbitMQ
Actually there is a call to query the Metadata but In GO, Java and .NET we have a High-Level client up to the Low-level TCP client and the easier way is something like:
var response = await client.CreateStream(spec.Name, spec.Args);
if (response.ResponseCode is ResponseCode.Ok or ResponseCode.StreamAlreadyExists)
return;
throw new CreateStreamException($"Failed to create stream, error code: {response.ResponseCode.ToString()}");
I think we can close this issue. using:
producer.create_stream('mystream', exists_ok=True)
It works
I am using the publisher example from the readme file.
First run
Please note that above error happens, when publishing a message to the stream. The related queue got created:
I can publish a message to the queue using Pika. Not sure, if it is configuration issue on my side...
Anyway, trying again to run the same publisher example
I would expect the stream to be reused when calling
Producer.create_stream
.