• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

synadia-io / nats.java.v3 / 38966765975

16 Oct 2026 09:04PM UTC coverage: 89.313% (-0.2%) from 89.5%
38966765975

push

github

scottf
Move push and pull subscribe out of JetStream into JsPushSubscribe and JsPullSubscribe

- The 15 pushSubscribe and 15 pullSubscribe overloads move to JsPushSubscribe and JsPullSubscribe (io.synadia.client.impl), each as an instance method (the constructor takes the JetStream) and as a static method (JetStream first parameter).
- KV/OS watch, OS get and the tests call the static form.
- README: new "Consuming from JetStream" section; the simplified API (ConsumerContext) is the preferred way to consume, the two classes exist only to support legacy behavior. jetstream README and migration guide updated.

4689 of 5499 branches covered (85.27%)

Branch coverage included in aggregate %.

71 of 110 new or added lines in 5 files covered. (64.55%)

1 existing line in 1 file now uncovered.

11649 of 12794 relevant lines covered (91.05%)

4.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.27
/jetstream/src/main/java/io/synadia/client/impl/JsPushSubscribe.java
1
// Copyright (c) 2026 Synadia Communications Inc. All Rights Reserved.
2

3
package io.synadia.client.impl;
4

5
import io.synadia.client.Dispatcher;
6
import io.synadia.client.MessageHandler;
7
import io.synadia.client.api.*;
8
import io.synadia.client.utils.Validator;
9
import org.jspecify.annotations.NonNull;
10
import org.jspecify.annotations.NullMarked;
11

12
import static io.synadia.client.utils.JetStreamClientError.JsSubNoMatchingStreamForSubject;
13
import static io.synadia.client.utils.Validator.validateSubject;
14

15
/**
16
 * The JetStream push subscribe methods. Use them through an instance made from a {@link JetStream},
17
 * or as static methods that take the {@link JetStream} as the first parameter:
18
 * <pre>
19
 * JetStreamPushSubscription sub = new JsPushSubscribe(js).pushSubscribe(stream, consumerName);
20
 * JetStreamPushSubscription sub = JsPushSubscribe.pushSubscribe(js, stream, consumerName);
21
 * </pre>
22
 * See {@link JsPullSubscribe} for pull subscriptions.
23
 */
24
@NullMarked
25
public class JsPushSubscribe {
26
    private final JetStream js;
27

28
    /**
29
     * Make the push subscribe methods for a JetStream context.
30
     * @param js the JetStream context
31
     */
NEW
32
    public JsPushSubscribe(@NonNull JetStream js) {
×
NEW
33
        this.js = Validator.required(js, "JetStream");
×
NEW
34
    }
×
35

36
    /**
37
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. Messages are
38
     * consumed synchronously from the returned subscription.
39
     * @param consumerInfo describes the consumer to bind to
40
     * @return the push subscription
41
     */
42
    public JetStreamPushSubscription pushSubscribe(ConsumerInfo consumerInfo) {
NEW
43
        return pushSubscribe(js, consumerInfo);
×
44
    }
45

46
    /**
47
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. Messages are
48
     * delivered asynchronously to {@code messageHandler} on a newly created {@link Dispatcher}.
49
     * @param consumerInfo describes the consumer to bind to
50
     * @param messageHandler the handler used to consume messages asynchronously; required
51
     * @return the push subscription
52
     * @throws IllegalArgumentException if {@code messageHandler} is null
53
     */
54
    public JetStreamPushSubscription pushSubscribe(ConsumerInfo consumerInfo, MessageHandler messageHandler) {
NEW
55
        return pushSubscribe(js, consumerInfo, messageHandler);
×
56
    }
57

58
    /**
59
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. The subscription
60
     * is set up according to {@code subscribeBehavior}.
61
     * @param consumerInfo describes the consumer to bind to
62
     * @param subscribeBehavior the behavior controlling the subscription; required
63
     * @return the push subscription
64
     * @throws IllegalArgumentException if {@code subscribeBehavior} is null
65
     */
66
    public JetStreamPushSubscription pushSubscribe(ConsumerInfo consumerInfo, SubscribeBehavior subscribeBehavior) {
NEW
67
        return pushSubscribe(js, consumerInfo, subscribeBehavior);
×
68
    }
69

70
    /**
71
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
72
     * is looked up on the server. Messages are consumed synchronously from the returned subscription.
73
     * @param stream the stream name
74
     * @param consumerName the name of the existing consumer
75
     * @return the push subscription
76
     * @throws JetStreamException covers communication and server-side JetStream errors
77
     * @throws InterruptedException if interrupted while waiting for the server
78
     */
79
    public JetStreamPushSubscription pushSubscribe(String stream, String consumerName) throws JetStreamException, InterruptedException {
NEW
80
        return pushSubscribe(js, stream, consumerName);
×
81
    }
82

83
    /**
84
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
85
     * is looked up on the server. Messages are delivered asynchronously to {@code messageHandler} on a
86
     * newly created {@link Dispatcher}.
87
     * @param stream the stream name
88
     * @param consumerName the name of the existing consumer
89
     * @param messageHandler the handler used to consume messages asynchronously; required
90
     * @return the push subscription
91
     * @throws JetStreamException covers communication and server-side JetStream errors
92
     * @throws InterruptedException if interrupted while waiting for the server
93
     * @throws IllegalArgumentException if {@code messageHandler} is null
94
     */
95
    public JetStreamPushSubscription pushSubscribe(String stream, String consumerName, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
NEW
96
        return pushSubscribe(js, stream, consumerName, messageHandler);
×
97
    }
98

99
    /**
100
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
101
     * is looked up on the server. The subscription is set up according to {@code subscribeBehavior}.
102
     * @param stream the stream name
103
     * @param consumerName the name of the existing consumer
104
     * @param subscribeBehavior the behavior controlling the subscription; required
105
     * @return the push subscription
106
     * @throws JetStreamException covers communication and server-side JetStream errors
107
     * @throws InterruptedException if interrupted while waiting for the server
108
     * @throws IllegalArgumentException if {@code subscribeBehavior} is null
109
     */
110
    public JetStreamPushSubscription pushSubscribe(String stream, String consumerName, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
NEW
111
        return pushSubscribe(js, stream, consumerName, subscribeBehavior);
×
112
    }
113

114
    /**
115
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
116
     * ephemeral, unnamed consumer is created on it. Messages are consumed synchronously from the
117
     * returned subscription.
118
     * @param subject the subject to subscribe to
119
     * @return the push subscription
120
     * @throws JetStreamException covers communication and server-side JetStream errors
121
     * @throws InterruptedException if interrupted while waiting for the server
122
     * @throws IllegalArgumentException if the subject is invalid
123
     * @throws IllegalStateException if no single stream carries the subject
124
     */
125
    public JetStreamPushSubscription pushSubscribe(String subject) throws JetStreamException, InterruptedException {
NEW
126
        return pushSubscribe(js, subject);
×
127
    }
128

129
    /**
130
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
131
     * ephemeral, unnamed consumer is created on it. Messages are delivered asynchronously to
132
     * {@code messageHandler} on a newly created {@link Dispatcher}.
133
     * @param subject the subject to subscribe to
134
     * @param messageHandler the handler used to consume messages asynchronously; required
135
     * @return the push subscription
136
     * @throws JetStreamException covers communication and server-side JetStream errors
137
     * @throws InterruptedException if interrupted while waiting for the server
138
     * @throws IllegalArgumentException if the subject is invalid or {@code messageHandler} is null
139
     * @throws IllegalStateException if no single stream carries the subject
140
     */
141
    public JetStreamPushSubscription pushSubscribe(String subject, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
NEW
142
        return pushSubscribe(js, subject, messageHandler);
×
143
    }
144

145
    /**
146
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
147
     * ephemeral, unnamed consumer is created on it. The subscription is set up according to
148
     * {@code subscribeBehavior}.
149
     * @param subject the subject to subscribe to
150
     * @param subscribeBehavior the behavior controlling the subscription; required
151
     * @return the push subscription
152
     * @throws JetStreamException covers communication and server-side JetStream errors
153
     * @throws InterruptedException if interrupted while waiting for the server
154
     * @throws IllegalArgumentException if the subject is invalid or {@code subscribeBehavior} is null
155
     * @throws IllegalStateException if no single stream carries the subject
156
     */
157
    public JetStreamPushSubscription pushSubscribe(String subject, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
NEW
158
        return pushSubscribe(js, subject, subscribeBehavior);
×
159
    }
160

161
    /**
162
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. Messages
163
     * are consumed synchronously from the returned subscription.
164
     * @param stream the stream name
165
     * @param creator describes the consumer to create
166
     * @return the push subscription
167
     * @throws JetStreamException covers communication and server-side JetStream errors
168
     * @throws InterruptedException if interrupted while waiting for the server
169
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name
170
     */
171
    public JetStreamPushSubscription pushSubscribe(String stream, PushConsumerCreator creator) throws JetStreamException, InterruptedException {
NEW
172
        return pushSubscribe(js, stream, creator);
×
173
    }
174

175
    /**
176
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. Messages
177
     * are delivered asynchronously to {@code messageHandler} on a newly created {@link Dispatcher}.
178
     * @param stream the stream name
179
     * @param creator describes the consumer to create
180
     * @param messageHandler the handler used to consume messages asynchronously; required
181
     * @return the push subscription
182
     * @throws JetStreamException covers communication and server-side JetStream errors
183
     * @throws InterruptedException if interrupted while waiting for the server
184
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code messageHandler} is null
185
     */
186
    public JetStreamPushSubscription pushSubscribe(String stream, PushConsumerCreator creator, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
NEW
187
        return pushSubscribe(js, stream, creator, messageHandler);
×
188
    }
189

190
    /**
191
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. The
192
     * subscription is set up according to {@code subscribeBehavior}.
193
     * @param stream the stream name
194
     * @param creator describes the consumer to create
195
     * @param subscribeBehavior the behavior controlling the subscription; required
196
     * @return the push subscription
197
     * @throws JetStreamException covers communication and server-side JetStream errors
198
     * @throws InterruptedException if interrupted while waiting for the server
199
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code subscribeBehavior} is null
200
     */
201
    public JetStreamPushSubscription pushSubscribe(String stream, PushConsumerCreator creator, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
NEW
202
        return pushSubscribe(js, stream, creator, subscribeBehavior);
×
203
    }
204

205
    /**
206
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
207
     * {@code stream}. Messages are consumed synchronously from the returned subscription.
208
     * @param stream the stream name
209
     * @param creator describes the ordered consumer to create
210
     * @return the push subscription
211
     * @throws JetStreamException covers communication and server-side JetStream errors
212
     * @throws InterruptedException if interrupted while waiting for the server
213
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name
214
     */
215
    public JetStreamPushSubscription pushSubscribe(String stream, PushOrderedConsumerCreator creator) throws JetStreamException, InterruptedException {
NEW
216
        return pushSubscribe(js, stream, creator);
×
217
    }
218

219
    /**
220
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
221
     * {@code stream}. Messages are delivered asynchronously to {@code messageHandler} on a newly
222
     * created {@link Dispatcher}.
223
     * @param stream the stream name
224
     * @param creator describes the ordered consumer to create
225
     * @param messageHandler the handler used to consume messages asynchronously; required
226
     * @return the push subscription
227
     * @throws JetStreamException covers communication and server-side JetStream errors
228
     * @throws InterruptedException if interrupted while waiting for the server
229
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code messageHandler} is null
230
     */
231
    public JetStreamPushSubscription pushSubscribe(String stream, PushOrderedConsumerCreator creator, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
NEW
232
        return pushSubscribe(js, stream, creator, messageHandler);
×
233
    }
234

235
    /**
236
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
237
     * {@code stream}. The subscription is set up according to {@code subscribeBehavior}.
238
     * @param stream the stream name
239
     * @param creator describes the ordered consumer to create
240
     * @param subscribeBehavior the behavior controlling the subscription; required
241
     * @return the push subscription
242
     * @throws JetStreamException covers communication and server-side JetStream errors
243
     * @throws InterruptedException if interrupted while waiting for the server
244
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code subscribeBehavior} is null
245
     */
246
    public JetStreamPushSubscription pushSubscribe(String stream, PushOrderedConsumerCreator creator, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
NEW
247
        return pushSubscribe(js, stream, creator, subscribeBehavior);
×
248
    }
249
    /**
250
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. Messages are
251
     * consumed synchronously from the returned subscription.
252
     * @param js the JetStream context
253
     * @param consumerInfo describes the consumer to bind to
254
     * @return the push subscription
255
     */
256
    public static JetStreamPushSubscription pushSubscribe(JetStream js, ConsumerInfo consumerInfo) {
257
        return (JetStreamPushSubscription) js._createJsSubscription(consumerInfo, null, null, null);
8 ✔
258
    }
259

260
    /**
261
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. Messages are
262
     * delivered asynchronously to {@code messageHandler} on a newly created {@link Dispatcher}.
263
     * @param js the JetStream context
264
     * @param consumerInfo describes the consumer to bind to
265
     * @param messageHandler the handler used to consume messages asynchronously; required
266
     * @return the push subscription
267
     * @throws IllegalArgumentException if {@code messageHandler} is null
268
     */
269
    public static JetStreamPushSubscription pushSubscribe(JetStream js, ConsumerInfo consumerInfo, MessageHandler messageHandler) {
270
        Validator.required(messageHandler, "MessageHandler");
4 ✔
271
        SubscribeBehavior subscribeBehavior = new SubscribeBehavior().handler(messageHandler);
6 ✔
272
        return (JetStreamPushSubscription) js._createJsSubscription(consumerInfo, subscribeBehavior, null, null);
8 ✔
273
    }
274

275
    /**
276
     * Push subscribe, binding to the consumer described by {@code consumerInfo}. The subscription
277
     * is set up according to {@code subscribeBehavior}.
278
     * @param js the JetStream context
279
     * @param consumerInfo describes the consumer to bind to
280
     * @param subscribeBehavior the behavior controlling the subscription; required
281
     * @return the push subscription
282
     * @throws IllegalArgumentException if {@code subscribeBehavior} is null
283
     */
284
    public static JetStreamPushSubscription pushSubscribe(JetStream js, ConsumerInfo consumerInfo, SubscribeBehavior subscribeBehavior) {
285
        Validator.required(subscribeBehavior, "SubscribeBehavior");
4 ✔
286
        return (JetStreamPushSubscription) js._createJsSubscription(consumerInfo, subscribeBehavior, null, null);
8 ✔
287
    }
288

289
    /**
290
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
291
     * is looked up on the server. Messages are consumed synchronously from the returned subscription.
292
     * @param js the JetStream context
293
     * @param stream the stream name
294
     * @param consumerName the name of the existing consumer
295
     * @return the push subscription
296
     * @throws JetStreamException covers communication and server-side JetStream errors
297
     * @throws InterruptedException if interrupted while waiting for the server
298
     */
299
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, String consumerName) throws JetStreamException, InterruptedException {
300
        return (JetStreamPushSubscription) js._createJsSubscription(js.strictGetConsumerInfo(stream, consumerName), null, null, null);
11 ✔
301
    }
302

303
    /**
304
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
305
     * is looked up on the server. Messages are delivered asynchronously to {@code messageHandler} on a
306
     * newly created {@link Dispatcher}.
307
     * @param js the JetStream context
308
     * @param stream the stream name
309
     * @param consumerName the name of the existing consumer
310
     * @param messageHandler the handler used to consume messages asynchronously; required
311
     * @return the push subscription
312
     * @throws JetStreamException covers communication and server-side JetStream errors
313
     * @throws InterruptedException if interrupted while waiting for the server
314
     * @throws IllegalArgumentException if {@code messageHandler} is null
315
     */
316
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, String consumerName, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
317
        Validator.required(messageHandler, "MessageHandler");
4 ✔
318
        SubscribeBehavior subscribeBehavior = new SubscribeBehavior().handler(messageHandler);
6 ✔
319
        return (JetStreamPushSubscription) js._createJsSubscription(js.strictGetConsumerInfo(stream, consumerName), subscribeBehavior, null, null);
11 ✔
320
    }
321

322
    /**
323
     * Push subscribe, binding to the existing consumer {@code consumerName} on {@code stream}, which
324
     * is looked up on the server. The subscription is set up according to {@code subscribeBehavior}.
325
     * @param js the JetStream context
326
     * @param stream the stream name
327
     * @param consumerName the name of the existing consumer
328
     * @param subscribeBehavior the behavior controlling the subscription; required
329
     * @return the push subscription
330
     * @throws JetStreamException covers communication and server-side JetStream errors
331
     * @throws InterruptedException if interrupted while waiting for the server
332
     * @throws IllegalArgumentException if {@code subscribeBehavior} is null
333
     */
334
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, String consumerName, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
335
        Validator.required(subscribeBehavior, "SubscribeBehavior");
4 ✔
336
        return (JetStreamPushSubscription) js._createJsSubscription(js.strictGetConsumerInfo(stream, consumerName), subscribeBehavior, null, null);
11 ✔
337
    }
338

339
    /**
340
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
341
     * ephemeral, unnamed consumer is created on it. Messages are consumed synchronously from the
342
     * returned subscription.
343
     * @param js the JetStream context
344
     * @param subject the subject to subscribe to
345
     * @return the push subscription
346
     * @throws JetStreamException covers communication and server-side JetStream errors
347
     * @throws InterruptedException if interrupted while waiting for the server
348
     * @throws IllegalArgumentException if the subject is invalid
349
     * @throws IllegalStateException if no single stream carries the subject
350
     */
351
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String subject) throws JetStreamException, InterruptedException {
352
        return pushSubscribe(js, subject, new SubscribeBehavior());
7 ✔
353
    }
354

355
    /**
356
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
357
     * ephemeral, unnamed consumer is created on it. Messages are delivered asynchronously to
358
     * {@code messageHandler} on a newly created {@link Dispatcher}.
359
     * @param js the JetStream context
360
     * @param subject the subject to subscribe to
361
     * @param messageHandler the handler used to consume messages asynchronously; required
362
     * @return the push subscription
363
     * @throws JetStreamException covers communication and server-side JetStream errors
364
     * @throws InterruptedException if interrupted while waiting for the server
365
     * @throws IllegalArgumentException if the subject is invalid or {@code messageHandler} is null
366
     * @throws IllegalStateException if no single stream carries the subject
367
     */
368
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String subject, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
369
        Validator.required(messageHandler, "MessageHandler");
4 ✔
370
        SubscribeBehavior subscribeBehavior = new SubscribeBehavior().handler(messageHandler);
6 ✔
371
        return pushSubscribe(js, subject, subscribeBehavior);
5 ✔
372
    }
373

374
    /**
375
     * Push subscribe to {@code subject}. The single stream carrying the subject is looked up and a new
376
     * ephemeral, unnamed consumer is created on it. The subscription is set up according to
377
     * {@code subscribeBehavior}.
378
     * @param js the JetStream context
379
     * @param subject the subject to subscribe to
380
     * @param subscribeBehavior the behavior controlling the subscription; required
381
     * @return the push subscription
382
     * @throws JetStreamException covers communication and server-side JetStream errors
383
     * @throws InterruptedException if interrupted while waiting for the server
384
     * @throws IllegalArgumentException if the subject is invalid or {@code subscribeBehavior} is null
385
     * @throws IllegalStateException if no single stream carries the subject
386
     */
387
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String subject, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
388
        subject = validateSubject(subject, true);
4 ✔
389
        Validator.required(subscribeBehavior, "SubscribeBehavior");
4 ✔
390
        String stream = js.lookupStreamBySubject(subject);
4 ✔
391
        if (stream == null) {
2 ✔
392
            throw JsSubNoMatchingStreamForSubject.instance();
5 ✔
393
        }
394
        PushConsumerCreator creator = new PushConsumerCreator().filterSubject(subject);
7 ✔
395
        return pushSubscribe(js, stream, creator, subscribeBehavior);
6 ✔
396
    }
397

398
    /**
399
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. Messages
400
     * are consumed synchronously from the returned subscription.
401
     * @param js the JetStream context
402
     * @param stream the stream name
403
     * @param creator describes the consumer to create
404
     * @return the push subscription
405
     * @throws JetStreamException covers communication and server-side JetStream errors
406
     * @throws InterruptedException if interrupted while waiting for the server
407
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name
408
     */
409
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushConsumerCreator creator) throws JetStreamException, InterruptedException {
410
        return pushSubscribe(js, stream, creator, new SubscribeBehavior());
8 ✔
411
    }
412

413
    /**
414
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. Messages
415
     * are delivered asynchronously to {@code messageHandler} on a newly created {@link Dispatcher}.
416
     * @param js the JetStream context
417
     * @param stream the stream name
418
     * @param creator describes the consumer to create
419
     * @param messageHandler the handler used to consume messages asynchronously; required
420
     * @return the push subscription
421
     * @throws JetStreamException covers communication and server-side JetStream errors
422
     * @throws InterruptedException if interrupted while waiting for the server
423
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code messageHandler} is null
424
     */
425
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushConsumerCreator creator, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
426
        Validator.required(messageHandler, "MessageHandler");
4 ✔
427
        SubscribeBehavior subscribeBehavior = new SubscribeBehavior().handler(messageHandler);
6 ✔
428
        return (JetStreamPushSubscription) js._createConsumerAndSubscription(stream, creator, subscribeBehavior);
7 ✔
429
    }
430

431
    /**
432
     * Push subscribe, creating the consumer described by {@code creator} on {@code stream}. The
433
     * subscription is set up according to {@code subscribeBehavior}.
434
     * @param js the JetStream context
435
     * @param stream the stream name
436
     * @param creator describes the consumer to create
437
     * @param subscribeBehavior the behavior controlling the subscription; required
438
     * @return the push subscription
439
     * @throws JetStreamException covers communication and server-side JetStream errors
440
     * @throws InterruptedException if interrupted while waiting for the server
441
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code subscribeBehavior} is null
442
     */
443
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushConsumerCreator creator, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
444
        Validator.required(subscribeBehavior, "SubscribeBehavior");
4 ✔
445
        return (JetStreamPushSubscription) js._createConsumerAndSubscription(stream, creator, subscribeBehavior);
7 ✔
446
    }
447

448
    /**
449
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
450
     * {@code stream}. Messages are consumed synchronously from the returned subscription.
451
     * @param js the JetStream context
452
     * @param stream the stream name
453
     * @param creator describes the ordered consumer to create
454
     * @return the push subscription
455
     * @throws JetStreamException covers communication and server-side JetStream errors
456
     * @throws InterruptedException if interrupted while waiting for the server
457
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name
458
     */
459
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushOrderedConsumerCreator creator) throws JetStreamException, InterruptedException {
460
        return pushSubscribe(js, stream, creator, new SubscribeBehavior());
8 ✔
461
    }
462

463
    /**
464
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
465
     * {@code stream}. Messages are delivered asynchronously to {@code messageHandler} on a newly
466
     * created {@link Dispatcher}.
467
     * @param js the JetStream context
468
     * @param stream the stream name
469
     * @param creator describes the ordered consumer to create
470
     * @param messageHandler the handler used to consume messages asynchronously; required
471
     * @return the push subscription
472
     * @throws JetStreamException covers communication and server-side JetStream errors
473
     * @throws InterruptedException if interrupted while waiting for the server
474
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code messageHandler} is null
475
     */
476
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushOrderedConsumerCreator creator, MessageHandler messageHandler) throws JetStreamException, InterruptedException {
477
        Validator.required(messageHandler, "MessageHandler");
4 ✔
478
        SubscribeBehavior subscribeBehavior = new SubscribeBehavior().handler(messageHandler);
6 ✔
479
        return pushSubscribe(js, stream, creator, subscribeBehavior);
6 ✔
480
    }
481

482
    /**
483
     * Push subscribe with an ordered consumer, creating the consumer described by {@code creator} on
484
     * {@code stream}. The subscription is set up according to {@code subscribeBehavior}.
485
     * @param js the JetStream context
486
     * @param stream the stream name
487
     * @param creator describes the ordered consumer to create
488
     * @param subscribeBehavior the behavior controlling the subscription; required
489
     * @return the push subscription
490
     * @throws JetStreamException covers communication and server-side JetStream errors
491
     * @throws InterruptedException if interrupted while waiting for the server
492
     * @throws IllegalArgumentException if the stream name is null, empty, or not a valid stream name, or if {@code subscribeBehavior} is null
493
     */
494
    public static JetStreamPushSubscription pushSubscribe(JetStream js, String stream, PushOrderedConsumerCreator creator, SubscribeBehavior subscribeBehavior) throws JetStreamException, InterruptedException {
495
        Validator.required(subscribeBehavior, "SubscribeBehavior");
4 ✔
496
        return (JetStreamPushSubscription) js._createConsumerAndSubscription(stream, creator, subscribeBehavior);
7 ✔
497
    }
498
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc