Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nats/src/nats/js/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ async def main():
if stream is None:
stream = await self._jsm.find_stream_name_by_subject(subject)

# Honor a durable name supplied through the config when the durable
# argument is omitted, so the consumer is created (and looked up) as a
# durable rather than a fresh ephemeral each call.
if durable is None and config is not None and config.durable_name:
durable = config.durable_name

should_create = True
try:
if durable:
Expand Down
16 changes: 16 additions & 0 deletions nats/tests/test_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ async def test_publish_msg_ttl(self):


class PullSubscribeTest(SingleJetStreamServerTestCase):
@async_test
async def test_pull_subscribe_honors_config_durable_name(self):
# Regression for #603: a durable_name supplied via ConsumerConfig must
# be honored when the durable argument is omitted, instead of silently
# creating a fresh ephemeral consumer.
nc = await nats.connect()
js = nc.jetstream()
await js.add_stream(name="pdur", subjects=["pdur"])

sub = await js.pull_subscribe("pdur", config=nats.js.api.ConsumerConfig(durable_name="mydurable"))
info = await sub.consumer_info()
assert info.name == "mydurable"
Comment thread
caspervonb marked this conversation as resolved.
assert info.config.durable_name == "mydurable"

await nc.close()

@async_test
async def test_auto_create_consumer(self):
nc = NATS()
Expand Down
Loading