nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegz <...@git.apache.org>
Subject [GitHub] nifi pull request: [REVIEW ONLY]]NIFI-865 added initial support fo...
Date Mon, 01 Feb 2016 16:50:26 GMT
Github user olegz commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/199#discussion_r51444249
  
    --- Diff: nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/main/java/org/apache/nifi/amqp/processors/AMQPPublisher.java
---
    @@ -0,0 +1,128 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.amqp.processors;
    +
    +import java.io.IOException;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import com.rabbitmq.client.AMQP.BasicProperties;
    +import com.rabbitmq.client.Connection;
    +import com.rabbitmq.client.ReturnListener;
    +
    +/**
    + * Generic publisher of messages to AMQP-based messaging system. It is based on
    + * RabbitMQ client API (https://www.rabbitmq.com/api-guide.html)
    + */
    +final class AMQPPublisher extends AMQPWorker {
    +
    +    private final static Logger logger = LoggerFactory.getLogger(AMQPPublisher.class);
    +
    +    private final String exchangeName;
    +
    +    private final String routingKey;
    +
    +    /**
    +     * Creates an instance of this publisher
    +     *
    +     * @param connection
    +     *            instance of AMQP {@link Connection}
    +     * @param exchangeName
    +     *            the name of AMQP exchange to which messages will be published.
    +     *            If not provided 'default' exchange will be used.
    +     * @param routingKey
    +     *            (required) the name of the routingKey to be used by AMQP-based
    +     *            system to route messages to its final destination (queue).
    +     */
    +    AMQPPublisher(Connection connection, String exchangeName, String routingKey) {
    +        super(connection);
    +        this.validateStringProperty("routingKey", routingKey);
    +        this.exchangeName = exchangeName == null ? "" : exchangeName.trim();
    +        if (this.exchangeName.length() == 0) {
    +            logger.info("The 'exchangeName' is not specified. Messages will be sent to
default exchange");
    +        }
    +
    +        this.routingKey = routingKey;
    +        this.channel.addReturnListener(new UndeliverableMessageLogger());
    +        logger.info("Successfully connected AMQPPublisher to " + connection.toString()
+ " and '" + this.exchangeName
    +                + "' exchange with '" + routingKey + "' as a routing key.");
    +    }
    +
    +    /**
    +     * Publishes message without any AMQP properties (see
    +     * {@link BasicProperties}) to a pre-defined AMQP Exchange.
    +     *
    +     * @param bytes
    +     *            bytes representing a message.
    +     */
    +    void publish(byte[] bytes) {
    +        this.publish(bytes, null);
    +    }
    +
    +    /**
    +     * Publishes message with provided AMQP properties (see
    +     * {@link BasicProperties}) to a pre-defined AMQP Exchange.
    +     *
    +     * @param bytes
    +     *            bytes representing a message.
    +     * @param properties
    +     *            instance of {@link BasicProperties}
    +     */
    +    void publish(byte[] bytes, BasicProperties properties) {
    +        if (this.channel.isOpen()) {
    +            try {
    +                this.channel.basicPublish(this.exchangeName, this.routingKey, true, properties,
bytes);
    +            } catch (Exception e) {
    +                throw new IllegalStateException("Failed to publish to '" +
    +                        this.exchangeName + "' with '" + this.routingKey + "'.", e);
    +            }
    +        } else {
    +            throw new IllegalStateException("This instance of AMQPPublisher is invalid
since "
    +                    + "its publishigChannel is closed");
    --- End diff --
    
    ClosedChannelException is checked exception, needed a runtime exception


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message