3

Is it possible to remove a subject from JetStream once the messages are subscribed.

For example if my stream is configured with subject orders.* and I have created one consumer with orders.new, is it possible to remove orders.new from stream.

Also in the above case how many topics will be created? Will it be only one topic with orders.* and consumer can listen to multiple subjects(orders.new, orders.processing)which will not be considered as new topic?

Please clarify how many subjects will be created in above example of orders.* with consumers listening to orders.new and orders.processing

user3212324
  • 163
  • 1
  • 6
  • 23

2 Answers2

1

To remove a subject from a JetStream you should remove all the messages with that subject from the stream. To do this you could use nats CLI utility from the NATS Tools and run:

nats stream purge JETSTREAMNAME --subject your.subject.name
Vladislav
  • 1,696
  • 27
  • 37
0

I think what you are looking for is the 'WorkingQueue' retention policy for your stream, which removes messages from the stream once they have been sent and acknowledged by a subscriber to a consumer on the stream.

So for example new order requests are published on 'orders.new.' and you have a stream with retention policy of 'WorkingQueue' listening on subject 'orders.new.*' and worker processes subscribe to a (durable, pull) consumer. Worker processes pull new orders from the stream and once the processing is done successfully they ack the message and it gets deleted form the requests stream. Be sure to adjust the consumer's 'AckWait' and/or use the 'give me more time to process' acknowledgement according to your processing times.

You can repeat this pattern to create workflows (e.g. message goes in the 'orders.new' stream, another message gets published to the 'orders.processing' stream and acked and therefore deleted from 'orders.new') or do long-lived request reply (like submitting a job) e.g. where the reply is published to 'results.' and you define a stream listening on 'results.*' (working queue, or time limit) and you can have the clients wait for the result of their order processing using an ephemeral consumer filtering on 'results.'.

JNM
  • 221
  • 2
  • 5