本文整理汇总了Java中org.apache.qpid.proton.amqp.messaging.Target类的典型用法代码示例。如果您正苦于以下问题:Java Target类的具体用法?Java Target怎么用?Java Target使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Target类属于org.apache.qpid.proton.amqp.messaging包,在下文中一共展示了Target类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newMockSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static ProtonSender newMockSender(final boolean drainFlag) {
@SuppressWarnings("rawtypes")
ArgumentCaptor<Handler> drainHandlerCaptor = ArgumentCaptor.forClass(Handler.class);
Record attachments = mock(Record.class);
ProtonSender sender = mock(ProtonSender.class);
when(sender.attachments()).thenReturn(attachments);
when(sender.isOpen()).thenReturn(Boolean.TRUE);
when(sender.getCredit()).thenReturn(DEFAULT_CREDITS);
when(sender.getQueued()).thenReturn(0);
when(sender.getDrain()).thenReturn(drainFlag);
when(sender.open()).then(invocation -> {
drainHandlerCaptor.getValue().handle(sender);
return sender;
});
when(sender.sendQueueDrainHandler(drainHandlerCaptor.capture())).then(invocation -> {
return sender;
});
Target target = new Target();
target.setAddress(DEFAULT_ADDRESS);
when(sender.getTarget()).thenReturn(target);
return sender;
}
示例2: sendMessage
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
public void sendMessage(String messageBody, long timeout, TimeUnit timeUnit) throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
protonClient.connect("127.0.0.1", protonServer.actualPort(), event -> {
ProtonConnection connection = event.result().open();
Target target = new Target();
target.setAddress(address);
target.setCapabilities(Symbol.getSymbol("topic"));
ProtonSender sender = connection.createSender(address);
sender.setTarget(target);
sender.open();
Message message = Message.Factory.create();
message.setBody(new AmqpValue(messageBody));
message.setAddress(address);
sender.send(message, delivery -> latch.countDown());
});
latch.await(timeout, timeUnit);
}
示例3: createDestination
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
private ActiveMQDestination createDestination(Object terminus) throws AmqpProtocolException {
if (terminus == null) {
return null;
} else if (terminus instanceof org.apache.qpid.proton.amqp.messaging.Source) {
org.apache.qpid.proton.amqp.messaging.Source source = (org.apache.qpid.proton.amqp.messaging.Source) terminus;
if (source.getAddress() == null || source.getAddress().length() == 0) {
throw new AmqpProtocolException("amqp:invalid-field", "source address not set");
}
return ActiveMQDestination.createDestination(source.getAddress(), ActiveMQDestination.QUEUE_TYPE);
} else if (terminus instanceof org.apache.qpid.proton.amqp.messaging.Target) {
org.apache.qpid.proton.amqp.messaging.Target target = (org.apache.qpid.proton.amqp.messaging.Target) terminus;
if (target.getAddress() == null || target.getAddress().length() == 0) {
throw new AmqpProtocolException("amqp:invalid-field", "target address not set");
}
return ActiveMQDestination.createDestination(target.getAddress(), ActiveMQDestination.QUEUE_TYPE);
} else if (terminus instanceof Coordinator) {
return null;
} else {
throw new RuntimeException("Unexpected terminus type: " + terminus);
}
}
示例4: doTestCreateDynamicSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void doTestCreateDynamicSender(boolean topic) throws Exception {
Target target = createDynamicTarget(topic);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(target);
assertNotNull(sender);
Target remoteTarget = (Target) sender.getEndpoint().getRemoteTarget();
assertTrue(remoteTarget.getDynamic());
assertTrue(remoteTarget.getDurable().equals(TerminusDurability.NONE));
assertTrue(remoteTarget.getExpiryPolicy().equals(TerminusExpiryPolicy.LINK_DETACH));
// Check the dynamic node lifetime-policy
Map<Symbol, Object> dynamicNodeProperties = remoteTarget.getDynamicNodeProperties();
assertTrue(dynamicNodeProperties.containsKey(LIFETIME_POLICY));
assertEquals(DeleteOnClose.getInstance(), dynamicNodeProperties.get(LIFETIME_POLICY));
Queue queueView = getProxyToQueue(remoteTarget.getAddress());
assertNotNull(queueView);
connection.close();
}
示例5: doTestDynamicSenderLifetimeBoundToLinkQueue
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
protected void doTestDynamicSenderLifetimeBoundToLinkQueue(boolean topic) throws Exception {
Target target = createDynamicTarget(topic);
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
AmqpSender sender = session.createSender(target);
assertNotNull(sender);
Target remoteTarget = (Target) sender.getEndpoint().getRemoteTarget();
Queue queueView = getProxyToQueue(remoteTarget.getAddress());
assertNotNull(queueView);
sender.close();
queueView = getProxyToQueue(remoteTarget.getAddress());
assertNull(queueView);
connection.close();
}
示例6: createDynamicTarget
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
protected Target createDynamicTarget(boolean topic) {
Target target = new Target();
target.setDynamic(true);
target.setDurable(TerminusDurability.NONE);
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
// Set the dynamic node lifetime-policy
Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
dynamicNodeProperties.put(LIFETIME_POLICY, DeleteOnClose.getInstance());
target.setDynamicNodeProperties(dynamicNodeProperties);
// Set the capability to indicate the node type being created
if (!topic) {
target.setCapabilities(TEMP_QUEUE_CAPABILITY);
} else {
target.setCapabilities(TEMP_TOPIC_CAPABILITY);
}
return target;
}
示例7: createSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
/**
* Create a sender instance using the given Target
*
* @param target the caller created and configured Target used to create the sender link.
* @param senderId the sender ID to assign to the newly created Sender.
* @param desiredCapabilities the capabilities that the caller wants the remote to support.
* @param offeredCapabilities the capabilities that the caller wants the advertise support for.
* @param properties the properties to send as part of the sender open.
* @return a newly created sender that is ready for use.
* @throws Exception if an error occurs while creating the receiver.
*/
public AmqpSender createSender(Target target, String senderId, Symbol[] desiredCapabilities, Symbol[] offeredCapabilities, Map<Symbol, Object> properties) throws Exception {
checkClosed();
final AmqpSender sender = new AmqpSender(AmqpSession.this, target, senderId);
sender.setDesiredCapabilities(desiredCapabilities);
sender.setOfferedCapabilities(offeredCapabilities);
sender.setProperties(properties);
final ClientFuture request = new ClientFuture();
connection.getScheduler().execute(new Runnable() {
@Override
public void run() {
checkClosed();
sender.setStateInspector(getStateInspector());
sender.open(request);
pumpToProtonTransport(request);
}
});
request.sync();
return sender;
}
示例8: doOpen
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
@Override
protected void doOpen() {
String sourceAddress = info.getName();
if (info.isQueue()) {
sourceAddress = connection.getTempQueuePrefix() + sourceAddress;
} else {
sourceAddress = connection.getTempQueuePrefix() + sourceAddress;
}
Source source = new Source();
source.setAddress(sourceAddress);
Target target = new Target();
target.setDynamic(true);
String senderName = sourceAddress;
endpoint = session.getProtonSession().sender(senderName);
endpoint.setSource(source);
endpoint.setTarget(target);
endpoint.setSenderSettleMode(SenderSettleMode.UNSETTLED);
endpoint.setReceiverSettleMode(ReceiverSettleMode.FIRST);
this.connection.addTemporaryDestination(this);
}
示例9: doOpen
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
@Override
protected void doOpen() {
JmsDestination destination = info.getDestination();
String destnationName = session.getQualifiedName(destination);
String sourceAddress = getProducerId().toString();
Source source = new Source();
source.setAddress(sourceAddress);
Target target = new Target();
target.setAddress(destnationName);
String senderName = sourceAddress + ":" + destnationName != null ? destnationName : "Anonymous";
endpoint = session.getProtonSession().sender(senderName);
endpoint.setSource(source);
endpoint.setTarget(target);
if (presettle) {
endpoint.setSenderSettleMode(SenderSettleMode.SETTLED);
} else {
endpoint.setSenderSettleMode(SenderSettleMode.UNSETTLED);
}
endpoint.setReceiverSettleMode(ReceiverSettleMode.FIRST);
}
示例10: createSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
private void createSender(CountDownLatch latch) {
ProtonClient protonClient = ProtonClient.create(vertx);
Endpoint endpoint = to.amqpEndpoint();
protonClient.connect(protonClientOptions, endpoint.hostname(), endpoint.port(), toConnection -> {
if (toConnection.succeeded()) {
log.info("Opened connection to destination broker for {}", queueInfo);
ProtonConnection toConn = toConnection.result();
toConn.setContainer("topic-migrator");
toConn.closeHandler(result -> {
log.info("Migrator connection for {} closed", queueInfo);
});
toConn.openHandler(toResult -> {
Target target = new Target();
target.setAddress(queueInfo.getAddress());
ProtonSender sender = toConn.createSender(queueInfo.getAddress());
sender.setTarget(target);
sender.closeHandler(res -> log.info("Sender connection for {} closed", queueInfo));
sender.openHandler(toRes -> {
if (toRes.succeeded()) {
log.info("Opened sender for {}, marking ready!", queueInfo);
createReceiver(latch, sender);
} else {
log.info("Error opening sender for {}: {}", queueInfo, toRes.cause().getMessage());
}
});
sender.open();
});
toConn.open();
} else {
log.info("Failed opening sender connection for {}: {}", queueInfo, toConnection.cause().getMessage());
}
});
}
示例11: publish
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
public void publish(Endpoint endpoint, String address, String content) throws InterruptedException {
String containerId = "test-publisher";
ProtonClient client = ProtonClient.create(vertx);
CountDownLatch latch = new CountDownLatch(1);
client.connect(endpoint.hostname(), endpoint.port(), connection -> {
if (connection.succeeded()) {
ProtonConnection conn = connection.result();
conn.setContainer(containerId);
conn.openHandler(result -> {
System.out.println("Connected: " + result.result().getRemoteContainer());
Target target = new Target();
target.setAddress(address);
target.setCapabilities(Symbol.getSymbol("topic"));
target.setDurable(TerminusDurability.UNSETTLED_STATE);
ProtonSender sender = conn.createSender(address);
sender.setTarget(target);
sender.openHandler(res -> {
if (res.succeeded()) {
System.out.println("Opened sender");
Message message = Message.Factory.create();
message.setAddress(address);
message.setBody(new AmqpValue(content));
sender.send(message, protonDelivery -> latch.countDown());
} else {
System.out.println("Failed opening sender: " + res.cause().getMessage());
}
});
sender.open();
});
conn.open();
} else {
System.out.println("Connection failed: " + connection.cause().getMessage());
}
});
latch.await(1, TimeUnit.MINUTES);
}
示例12: createSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
private void createSender(org.apache.qpid.proton.engine.Session session) throws Exception {
Sender sender = session.sender(subscriberInfo.getClientId());
Target target = new Target();
target.setAddress(subscriberInfo.getClientAddress());
sender.setTarget(target);
Source source = new Source();
source.setAddress(subscriberInfo.getClientAddress());
source.setDurable(TerminusDurability.UNSETTLED_STATE);
sender.setSource(source);
sender.open();
}
示例13: startSender
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
private void startSender() {
ProtonClient client = ProtonClient.create(vertx);
log.info(this + ": starting sender");
client.connect(getOptions(), to.hostname(), to.port(), event -> {
if (event.succeeded()) {
ProtonConnection connection = event.result();
connection.open();
senderConnection = Optional.of(connection);
ProtonSender sender = connection.createSender(address);
sender.openHandler(handler -> {
log.info(this + ": sender opened to " + connection.getRemoteContainer());
startReceiver(sender, connection.getRemoteContainer());
});
sender.closeHandler(result -> {
if (result.succeeded()) {
log.info(this + ": sender closed");
closeReceiver();
} else {
closeReceiver();
log.warn(this + ": sender closed with error: " + result.cause().getMessage());
vertx.setTimer(connectionRetryInterval, timerId -> startSender());
}
});
Target target = new Target();
target.setAddress(address);
target.setCapabilities(topic);
sender.setTarget(target);
sender.open();
} else {
closeReceiver();
log.info(this + ": connection failed: " + event.cause().getMessage());
vertx.setTimer(connectionRetryInterval, timerId -> startSender());
}
});
}
示例14: recvMessages
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
public Future<List<Message>> recvMessages(Source source, Predicate<Message> done, Optional<String> linkName, long connectTimeout, TimeUnit timeUnit) throws InterruptedException, IOException, ConnectTimeoutException {
CompletableFuture<List<Message>> promise = new CompletableFuture<>();
CountDownLatch connectLatch = new CountDownLatch(1);
Vertx vertx = VertxFactory.create();
clients.add(vertx);
vertx.deployVerticle(new Receiver(options, done, promise, new LinkOptions(source, new Target(), linkName), connectLatch));
if (!connectLatch.await(connectTimeout, timeUnit)) {
throw new ConnectTimeoutException("Timeout waiting for client to connect");
}
return promise;
}
示例15: newOutgoing
import org.apache.qpid.proton.amqp.messaging.Target; //导入依赖的package包/类
public Sender newOutgoing(Session ssn, String remote, String local) {
Sender snd = ssn.sender(String.format("%s-%s", local, remote));
Source src = new Source();
src.setAddress(local);
snd.setSource(src);
Target tgt = new Target();
tgt.setAddress(remote);
snd.setTarget(tgt);
return snd;
}