本文整理汇总了Java中io.vertx.proton.ProtonSender.setSource方法的典型用法代码示例。如果您正苦于以下问题:Java ProtonSender.setSource方法的具体用法?Java ProtonSender.setSource怎么用?Java ProtonSender.setSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.proton.ProtonSender
的用法示例。
在下文中一共展示了ProtonSender.setSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleSenderOpen
import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
/**
* Handles a request from a client to establish a link for receiving messages from this server.
*
* @param con the connection to the client.
* @param sender the sender created for the link.
*/
@Override
protected void handleSenderOpen(final ProtonConnection con, final ProtonSender sender) {
final Source remoteSource = sender.getRemoteSource();
LOG.debug("client [{}] wants to open a link for receiving messages [address: {}]",
con.getRemoteContainer(), remoteSource);
try {
final ResourceIdentifier targetResource = getResourceIdentifier(remoteSource.getAddress());
final AmqpEndpoint endpoint = getEndpoint(targetResource);
if (endpoint == null) {
LOG.debug("no endpoint registered for node [{}]", targetResource);
con.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such node")).close();
} else {
HonoUser user = Constants.getClientPrincipal(con);
if (Constants.SUBJECT_ANONYMOUS.equals(user.getName())) {
con.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS, "client must authenticate using SASL")).close();
} else {
Constants.copyProperties(con, sender);
sender.setSource(sender.getRemoteSource());
endpoint.onLinkAttach(con, sender, targetResource);
vertx.setTimer(5000, closeCon -> {
if (!con.isDisconnected()) {
LOG.debug("connection with client [{}] timed out after 5 seconds, closing connection", con.getRemoteContainer());
con.setCondition(ProtonHelper.condition("hono: inactivity", "client must retrieve token within 5 secs after opening connection")).close();
}
});
}
}
} catch (final IllegalArgumentException e) {
LOG.debug("client has provided invalid resource identifier as source address", e);
con.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD, "malformed source address")).close();
}
}
示例2: senderOpenHandler
import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
private void senderOpenHandler(ProtonConnection connection, ProtonSender sender) {
sender.setSource(sender.getRemoteSource());
Source source = (Source) sender.getRemoteSource();
log.info("Got subscription request from {} on {}", connection.getRemoteContainer(), source.getAddress());
Context protonContext = vertx.getOrCreateContext();
vertx.executeBlocking(promise -> {
try {
ResourceDatabase database = lookupDatabase(source.getAddress());
Map<String, String> labelFilter = createLabelFilter(source.getFilter());
Map<String, String> annotationFilter = createAnnotationFilter(source.getFilter());
ObserverKey subscriptionKey = new ObserverKey(labelFilter, annotationFilter);
database.subscribe(subscriptionKey, new AMQPSubscriber(protonContext, subscriptionKey, connection, sender));
promise.complete(database);
} catch (Exception e) {
promise.fail(e);
}
}, result -> {
if (result.succeeded()) {
sender.open();
log.info("Added subscriber {} for config {}", connection.getRemoteContainer(), sender.getRemoteSource().getAddress());
} else {
sender.close();
connection.close();
log.info("Failed creating subscriber {} for config {}", connection.getRemoteContainer(), sender.getRemoteSource().getAddress(), result.cause());
}
});
}