本文整理汇总了Java中com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder类的典型用法代码示例。如果您正苦于以下问题:Java SubscribeOptionsBuilder类的具体用法?Java SubscribeOptionsBuilder怎么用?Java SubscribeOptionsBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SubscribeOptionsBuilder类属于com.ibm.mqlight.api.SubscribeOptions包,在下文中一共展示了SubscribeOptionsBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSubscribeOptions
import com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder; //导入依赖的package包/类
/**
* @return
*/
public SubscribeOptions getSubscribeOptions() {
SubscribeOptionsBuilder sob = SubscribeOptions.builder();
if (autoConfirm != null) sob.setAutoConfirm(autoConfirm == AUTO_CONFIRM.AUTO);
if (linkCredit != null) sob.setCredit(linkCredit);
if (qos != null) sob.setQos(qos);
if (shareName != null) sob.setShare(shareName);
if (ttl != null) sob.setTtl(ttl);
return sob.build();
}
示例2: unsubscribeFromWithinMessageCallbackTemplate
import com.ibm.mqlight.api.SubscribeOptions.SubscribeOptionsBuilder; //导入依赖的package包/类
private void unsubscribeFromWithinMessageCallbackTemplate(QOS qos, final boolean shared, boolean autoConfirm,
final boolean confirmBeforeUnsubscribe, final boolean confirmAfterUnsubscribe) throws Exception {
MockComponent engine = new MockComponent();
MockNonBlockingClientListener listener = new MockNonBlockingClientListener(false);
final NonBlockingClientImpl client = openCommon(engine, listener);
EngineConnection engineConnection = new EngineConnection();
OpenRequest openRequest = (OpenRequest)engine.getMessages().get(0);
client.tell(new OpenResponse(openRequest, engineConnection), engine);
SubscribeOptionsBuilder subOptsBuilder = SubscribeOptions.builder();
subOptsBuilder.setQos(qos);
if (qos == QOS.AT_LEAST_ONCE) {
subOptsBuilder.setAutoConfirm(autoConfirm);
}
if (shared) {
subOptsBuilder.setShare("share");
}
SubscribeOptions subOpts = subOptsBuilder.build();
final Semaphore done = new Semaphore(0);
final MockCompletionListener subscribeListener = new MockCompletionListener();
final MockCompletionListener unsubscribeListener = new MockCompletionListener();
client.subscribe("/kittens", subOpts, new DestinationAdapter<Void>() {
@Override
public void onMessage(NonBlockingClient client2, Void context, Delivery delivery) {
if (confirmBeforeUnsubscribe) {
delivery.confirm();
}
if (shared) {
client.unsubscribe("/kittens", "share", unsubscribeListener, null);
} else {
client.unsubscribe("/kittens", unsubscribeListener, null);
}
if (confirmAfterUnsubscribe) {
delivery.confirm();
}
done.release();
}
}, subscribeListener, null);
client.tell(new SubscribeResponse(engineConnection, new SubscriptionTopic("/kittens", shared ? "share" : null)), engine);
subscribeListener.assertSuccess();
byte[] amqpMessageData = TestDestinationListenerWrapper.createSerializedProtonMessage(
new AmqpValue(new Binary(new byte[]{1})), "/kittens", 0, null, null, null);
client.tell(new DeliveryRequest(amqpMessageData, qos,
shared ? "share:share:/kittens" : "private:/kittens", null, null), engine);
assertTrue("Client failed to receive message within timeout. ", done.tryAcquire(4, TimeUnit.SECONDS));
LinkedList<Message> messages = engine.getMessages();
boolean notConfirmed = (qos == QOS.AT_LEAST_ONCE) && !autoConfirm && !confirmBeforeUnsubscribe && !confirmAfterUnsubscribe;
assertEquals("Engine received wrong number of events", notConfirmed ? 3 : 4, messages.size());
int i = 0;
assertEquals("Event #" + (i + 1) + " should have been OpenRequest", OpenRequest.class, messages.get(i++).getClass());
assertEquals("Event #" + (i + 1) + " should have been SubscribeRequest", SubscribeRequest.class, messages.get(i++).getClass());
if (!notConfirmed) {
assertEquals("Event #" + (i + 1) + " should have been DeliveryResponse", DeliveryResponse.class, messages.get(i++).getClass());
}
assertEquals("Event #" + (i + 1) + " should have been UnsubscribeRequest", UnsubscribeRequest.class, messages.get(i++).getClass());
client.tell(messages.get(2), engine);
client.tell(new UnsubscribeResponse(engineConnection, new SubscriptionTopic("/kittens", shared ? "share" : null), null), engine);
unsubscribeListener.assertSuccess();
}