nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markap14 <...@git.apache.org>
Subject [GitHub] nifi pull request: NIFI-865 added initial support for AMQP publish...
Date Tue, 02 Feb 2016 17:22:37 GMT
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/200#discussion_r51601774
  
    --- Diff: nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/main/java/org/apache/nifi/amqp/processors/AMQPPublisher.java
---
    @@ -0,0 +1,134 @@
    +/*
    + * 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.apache.nifi.logging.ProcessorLog;
    +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;
    +
    +    private final ProcessorLog processLog;
    +
    +    /**
    +     * 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, ProcessorLog
processLog) {
    +        super(connection);
    +        this.processLog = processLog;
    +        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");
    +        }
    +    }
    +
    +    /**
    +     *
    +     */
    +    @Override
    +    public String toString() {
    +        return super.toString() + ", EXCHANGE:" + this.exchangeName + ", ROUTING_KEY:"
+ this.routingKey;
    +    }
    +
    +    /**
    +     * Listener to listen and WARN-log undeliverable messages which are returned
    --- End diff --
    
    If I am understanding this comment correctly, it is possible, if the AMQP Broker is not
setup properly, to lose messages? Is that accurate? If so, I think we need to be sure to explicitly
state this in the PublishAMQP's @CapabilityDescription


---
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