当前位置: 首页>>代码示例>>Java>>正文


Java ProtonSender.setSource方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:41,代码来源:SimpleAuthenticationServer.java

示例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());
        }
    });
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:31,代码来源:AMQPServer.java


注:本文中的io.vertx.proton.ProtonSender.setSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。