本文整理汇总了Java中io.vertx.proton.ProtonSender.getRemoteSource方法的典型用法代码示例。如果您正苦于以下问题:Java ProtonSender.getRemoteSource方法的具体用法?Java ProtonSender.getRemoteSource怎么用?Java ProtonSender.getRemoteSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.proton.ProtonSender
的用法示例。
在下文中一共展示了ProtonSender.getRemoteSource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.
*/
protected void handleSenderOpen(final ProtonConnection con, final ProtonSender sender) {
final Source remoteSource = sender.getRemoteSource();
LOG.debug("client [container: {}] wants to open a link [address: {}] for receiving messages",
con.getRemoteContainer(), remoteSource);
try {
final ResourceIdentifier targetResource = getResourceIdentifier(remoteSource.getAddress());
final AmqpEndpoint endpoint = getEndpoint(targetResource);
if (endpoint == null) {
handleUnknownEndpoint(con, sender, targetResource);
} else {
final HonoUser user = Constants.getClientPrincipal(con);
getAuthorizationService().isAuthorized(user, targetResource, Activity.READ).setHandler(authAttempt -> {
if (authAttempt.succeeded() && authAttempt.result()) {
Constants.copyProperties(con, sender);
sender.setSource(sender.getRemoteSource());
endpoint.onLinkAttach(con, sender, targetResource);
} else {
LOG.debug("subject [{}] is not authorized to READ from [{}]", user.getName(), targetResource);
sender.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "unauthorized"));
sender.close();
}
});
}
} catch (final IllegalArgumentException e) {
LOG.debug("client has provided invalid resource identifier as target address", e);
sender.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such address"));
sender.close();
}
}
示例3: 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());
}
});
}