Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] when specifying a bind, if the consumer didn't specify deliver_to get flagged as pull #269

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions nats-base-client/jsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ export class JetStreamClientImpl extends BaseApiClient
const cso = await this._processOptions(subject, opts);
// this effectively requires deliver subject to be specified
// as an option otherwise we have a pull consumer
if (!cso.config.deliver_subject) {
if (!cso.isBind && !cso.config.deliver_subject) {
throw new Error(
"consumer info specifies a pull consumer - deliver_subject is required",
"push consumer requires deliver_subject",
);
}

Expand Down
56 changes: 55 additions & 1 deletion tests/jetstream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ Deno.test("jetstream - pull consumer info without pull", async () => {
await js.subscribe(subj, sopts);
},
Error,
"consumer info specifies a pull consumer",
"push consumer requires deliver_subject",
undefined,
);

Expand Down Expand Up @@ -2899,3 +2899,57 @@ Deno.test("jetstream - bind example", async () => {

await cleanup(ns, nc);
});

Deno.test("jetstream - test events stream", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const js = nc.jetstream();
const jsm = await nc.jetstreamManager();
await jsm.streams.add({
name: "events",
subjects: ["events.>"],
});

const sub = await js.subscribe("events.>", {
stream: "events",
config: {
ack_policy: AckPolicy.Explicit,
deliver_policy: DeliverPolicy.All,
deliver_subject: "foo",
durable_name: "me",
filter_subject: "events.>",
},
callbackFn: (err: NatsError | null, msg: JsMsg | null) => {
msg?.ack();
},
});

await js.publish("events.a");
await js.publish("events.b");
await delay(2000);
await cleanup(ns, nc);
});

Deno.test("jetstream - bind without consumer should fail", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const js = nc.jetstream();
const jsm = await nc.jetstreamManager();
await jsm.streams.add({
name: "events",
subjects: ["events.>"],
});

const opts = consumerOpts();
opts.manualAck();
opts.ackExplicit();
opts.bind("events", "hello");

await assertRejects(
async () => {
await js.subscribe("events.>", opts);
},
Error,
"unable to bind - durable consumer hello doesn't exist in events",
);

await cleanup(ns, nc);
});
1 change: 0 additions & 1 deletion tests/jsm_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ Deno.test("jsm - jetstream error info", async () => {
const ne = err as NatsError;
assert(ne.isJetStreamError());
const jerr = ne.jsError();
console.log(jerr);
assert(jerr);
assertEquals(jerr.code, 500);
assertEquals(jerr.err_code, 10074);
Expand Down