[ 
https://issues.apache.org/jira/browse/NIFI-865?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15128583#comment-15128583
 ] 

ASF GitHub Bot commented on NIFI-865:
-------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/200#discussion_r51600077
  
    --- Diff: 
nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/main/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessor.java
 ---
    @@ -0,0 +1,204 @@
    +/*
    + * 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 java.lang.reflect.Field;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.nifi.annotation.lifecycle.OnStopped;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.processor.AbstractProcessor;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.Processor;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processor.util.StandardValidators;
    +
    +import com.rabbitmq.client.Connection;
    +import com.rabbitmq.client.ConnectionFactory;
    +
    +/**
    + * Base processor that uses RabbitMQ client API
    + * (https://www.rabbitmq.com/api-guide.html) to rendezvous with AMQP-based
    + * messaging systems version 0.9.1
    + *
    + * @param <T> the type of {@link AMQPWorker}. Please see {@link 
AMQPPublisher}
    + *            and {@link AMQPConsumer}
    + */
    +abstract class AbstractAMQPProcessor<T extends AMQPWorker> extends 
AbstractProcessor {
    +
    +    public static final PropertyDescriptor HOST = new 
PropertyDescriptor.Builder()
    +            .name("Host Name")
    +            .description("Network address of AMQP broker (e.g., 
localhost)")
    +            .required(true)
    +            .defaultValue("localhost")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor PORT = new 
PropertyDescriptor.Builder()
    +            .name("Port")
    +            .description("Numeric value identifying Port of AMQP broker 
(e.g., 5671)")
    +            .required(true)
    +            .defaultValue("5672")
    +            .addValidator(StandardValidators.PORT_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor V_HOST = new 
PropertyDescriptor.Builder()
    +            .name("Virtual Host")
    +            .description("Virtual Host name which segregates AMQP system 
for enhanced security.")
    +            .required(false)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor USER = new 
PropertyDescriptor.Builder()
    +            .name("User Name")
    +            .description("User Name used for authentication and 
authorization.")
    +            .required(true)
    +            .defaultValue("guest")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor PASSWORD = new 
PropertyDescriptor.Builder()
    +            .name("Password")
    +            .description("Password used for authentication and 
authorization.")
    +            .required(true)
    +            .defaultValue("guest")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .sensitive(true)
    +            .build();
    +    public static final PropertyDescriptor AMQP_VERSION = new 
PropertyDescriptor.Builder()
    +            .name("AMQP Version")
    +            .description("AMQP Version. Currently only supports AMQP 
v0.9.1.")
    +            .required(true)
    +            .allowableValues("0.9.1")
    +            .defaultValue("0.9.1")
    +            .build();
    +
    +    static List<PropertyDescriptor> descriptors = new ArrayList<>();
    +
    +    /*
    +     * Will ensure that list of PropertyDescriptors is build only once, 
since
    +     * all other lifecycle methods are invoked multiple times
    +     */
    +    static {
    +        Field[] fields = AbstractAMQPProcessor.class.getDeclaredFields();
    +        try {
    +            for (Field field : fields) {
    +                field.setAccessible(true);
    +                if 
(PropertyDescriptor.class.isAssignableFrom(field.getType())) {
    +                    descriptors.add((PropertyDescriptor) field.get(null));
    +                }
    +            }
    +        } catch (Exception e) {
    +            throw new IllegalStateException("Failed to build 
PropertyDescriptor list", e);
    +        }
    +    }
    +
    +    protected volatile Connection amqpConnection;
    +
    +    protected volatile T targetResource;
    +
    +    /**
    +     * Will builds target resource ({@link AMQPPublisher} or
    +     * {@link AMQPConsumer}) upon first invocation and will delegate to the
    +     * implementation of
    +     * {@link #rendezvousWithAmqp(ProcessContext, ProcessSession)} method 
for
    +     * further processing.
    +     */
    +    @Override
    +    public void onTrigger(ProcessContext context, ProcessSession session) 
throws ProcessException {
    +        synchronized (this) {
    +            this.buildTargetResource(context);
    +        }
    +        this.rendezvousWithAmqp(context, session);
    +    }
    +
    +    /**
    +     * Will close current AMQP connection.
    +     */
    +    @OnStopped
    +    public void close() {
    +        try {
    +            this.targetResource.close();
    --- End diff --
    
    If the call to createConnection() were to throw an Exception, both 
targetResource and amqpConnection could be closed. Should check if these 
objects are null before calling close()


> Add processors to Get and Put to/from AMQP-based messaging systems
> ------------------------------------------------------------------
>
>                 Key: NIFI-865
>                 URL: https://issues.apache.org/jira/browse/NIFI-865
>             Project: Apache NiFi
>          Issue Type: Wish
>          Components: Extensions
>            Reporter: Joseph Witt
>            Assignee: Oleg Zhurakousky
>              Labels: beginner
>             Fix For: 0.5.0
>
>
> David Smith in the mailing list has already begun work on this.  The link to 
> his current set of code in Github is here:  
> https://github.com/helicopterman22/nifi_amqp_processors
> He is seeking help with licensing/unit testing/etc.. so that it can end up in 
> a build.
> We have word from another user now that they too are interested in this.  
> They specifically are using RabbitMQ but we should be able to implement 
> (ideally) a pure AMQP protocol friendly version and be good to go.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to