You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by subhankarb <gi...@git.apache.org> on 2016/05/31 10:42:19 UTC

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize ...

GitHub user subhankarb opened a pull request:

    https://github.com/apache/flink/pull/2054

    [FLINK-3763] RabbitMQ Source/Sink standardize connection parameters

    Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
    If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the [How To Contribute guide](http://flink.apache.org/how-to-contribute.html).
    In addition to going through the list, please provide a meaningful description of your changes.
    
    - [x] General
      - The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
      - The pull request addresses only one issue
      - Each commit in the PR has a meaningful commit message (including the JIRA id)
    
    - [x] Documentation
      - Documentation has been added for new functionality
      - Old documentation affected by the pull request has been updated
      - JavaDoc for public methods has been added
    
    - [x] Tests & Build
      - Functionality added by the pull request is covered by tests
      - `mvn clean verify` has been executed successfully locally or a Travis build has passed
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/subhankarb/flink FLINK-3763

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/2054.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2054
    
----
commit 0894679aa7dfbb8e0d5f6edd51f5000a08707769
Author: subhankar <su...@target.com>
Date:   2016-05-31T10:38:27Z

    [FLINK-3763] RabbitMQ Source/Sink standardize connection parameters

----


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65328505
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    +     */
    +	private RMQConnectionConfig(String uri, int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(uri, "Uri can not be null");
    +		this.uri = uri;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/** @return the host to use for connections */
    +	public String getHost() {
    +		return host;
    +	}
    +
    +	/** @return the port to use for connections */
    +	public int getPort() {
    +		return port;
    +	}
    +
    +	/**
    +	 * Retrieve the virtual host.
    +	 * @return the virtual host to use when connecting to the broker
    +	 */
    +	public String getVirtualHost() {
    +		return virtualHost;
    +	}
    +
    +	/**
    +	 * Retrieve the user name.
    +	 * @return the AMQP user name to use when connecting to the broker
    +	 */
    +	public String getUsername() {
    +		return username;
    +	}
    +
    +	/**
    +	 * Retrieve the password.
    +	 * @return the password to use when connecting to the broker
    +	 */
    +	public String getPassword() {
    +		return password;
    +	}
    +
    +	/**
    +	 * Retrieve the URI.
    +	 * @return the connection URI when connecting to the broker
    +     */
    +	public String getUri() {
    +		return uri;
    +	}
    +
    +	/**
    +	 * Returns automatic connection recovery interval in milliseconds.
    +	 * @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
    +	 */
    +	public int getNetworkRecoveryInterval() {
    +		return networkRecoveryInterval;
    +	}
    +
    +	/**
    +	 * Returns true if automatic connection recovery is enabled, false otherwise
    +	 * @return true if automatic connection recovery is enabled, false otherwise
    +	 */
    +	public boolean isAutomaticRecovery() {
    +		return automaticRecovery;
    +	}
    +
    +	/**
    +	 * Returns true if topology recovery is enabled, false otherwise
    +	 * @return true if topology recovery is enabled, false otherwise
    +	 */
    +	public boolean isTopologyRecovery() {
    +		return topologyRecovery;
    +	}
    +
    +	/**
    +	 * Retrieve the connection timeout.
    +	 * @return the connection timeout, in milliseconds; zero for infinite
    +	 */
    +	public int getConnectionTimeout() {
    +		return connectionTimeout;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum channel number
    +	 * @return the initially requested maximum channel number; zero for unlimited
    +	 */
    +	public int getRequestedChannelMax() {
    +		return requestedChannelMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum frame size
    +	 * @return the initially requested maximum frame size, in octets; zero for unlimited
    +	 */
    +	public int getRequestedFrameMax() {
    +		return requestedFrameMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested heartbeat interval.
    +	 * @return the initially requested heartbeat interval, in seconds; zero for none
    +	 */
    +	public int getRequestedHeartbeat() {
    +		return requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @return Connection Factory for RMQ
    +	 * @throws Exception if Malformed URI has been passed
    +     */
    +	public ConnectionFactory getConnectionFactory() throws Exception {
    +		ConnectionFactory factory = new ConnectionFactory();
    +		if (this.uri != null && !this.uri.isEmpty()){
    +			try {
    +				factory.setUri(getUri());
    +			}catch (Exception e){
    +				LOG.error("Failed to parse uri {}", e.getMessage());
    +				throw e;
    +			}
    +		} else {
    +			factory.setHost(getHost());
    +			factory.setPort(getPort());
    +			factory.setVirtualHost(getVirtualHost());
    +			factory.setUsername(getUsername());
    +			factory.setPassword(getPassword());
    +		}
    +
    +		factory.setAutomaticRecoveryEnabled(isAutomaticRecovery());
    +		factory.setConnectionTimeout(getConnectionTimeout());
    +		factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
    +		factory.setRequestedHeartbeat(getRequestedHeartbeat());
    +		factory.setTopologyRecoveryEnabled(isTopologyRecovery());
    +		factory.setRequestedChannelMax(getRequestedChannelMax());
    +		factory.setRequestedFrameMax(getRequestedFrameMax());
    +
    +		return factory;
    +	}
    +
    +	public static class Builder {
    +		/** The default host */
    +		public static final String DEFAULT_HOST = "localhost";
    --- End diff --
    
    Okay, I didn't check all the fields in the ConnectionFactory, sorry.
    
    Your proposal sounds good.


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

[GitHub] flink issue #2054: [FLINK-3763] RabbitMQ Source/Sink standardize connection ...

Posted by subhankarb <gi...@git.apache.org>.
Github user subhankarb commented on the issue:

    https://github.com/apache/flink/pull/2054
  
    Hi @rmetzger ,
    would you plzzz review the changes.



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

[GitHub] flink issue #2054: [FLINK-3763] RabbitMQ Source/Sink standardize connection ...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on the issue:

    https://github.com/apache/flink/pull/2054
  
    Okay, I reviewed your pull request and I like it ;)
    I'll merge your pull request together with some general RMQ cleanups: https://github.com/rmetzger/flink/commit/0a60c02abc68757b2a873e6bf70bb7bec81e9885


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65253162
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSink.java ---
    @@ -35,24 +36,28 @@
     	private static final Logger LOG = LoggerFactory.getLogger(RMQSink.class);
     
     	private String QUEUE_NAME;
    -	private String HOST_NAME;
    +	private RMQConnectionConfig rmqConnectionConfig;
     	private transient ConnectionFactory factory;
     	private transient Connection connection;
     	private transient Channel channel;
     	private SerializationSchema<IN> schema;
     
    -	public RMQSink(String HOST_NAME, String QUEUE_NAME, SerializationSchema<IN> schema) {
    -		this.HOST_NAME = HOST_NAME;
    +	/**
    +	 * @param rmqConnectionConfig The RabbiMQ connection configuration {@link RMQConnectionConfig}.
    +	 * @param QUEUE_NAME The queue to publish messages to.
    +	 * @param schema A {@link SerializationSchema} for turning the Java objects received into bytes
    +     */
    +	public RMQSink(RMQConnectionConfig rmqConnectionConfig, String QUEUE_NAME, SerializationSchema<IN> schema) {
    --- End diff --
    
    Same here with the QUEUE_NAME


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by subhankarb <gi...@git.apache.org>.
Github user subhankarb commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65303646
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    +     */
    +	private RMQConnectionConfig(String uri, int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(uri, "Uri can not be null");
    +		this.uri = uri;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/** @return the host to use for connections */
    +	public String getHost() {
    +		return host;
    +	}
    +
    +	/** @return the port to use for connections */
    +	public int getPort() {
    +		return port;
    +	}
    +
    +	/**
    +	 * Retrieve the virtual host.
    +	 * @return the virtual host to use when connecting to the broker
    +	 */
    +	public String getVirtualHost() {
    +		return virtualHost;
    +	}
    +
    +	/**
    +	 * Retrieve the user name.
    +	 * @return the AMQP user name to use when connecting to the broker
    +	 */
    +	public String getUsername() {
    +		return username;
    +	}
    +
    +	/**
    +	 * Retrieve the password.
    +	 * @return the password to use when connecting to the broker
    +	 */
    +	public String getPassword() {
    +		return password;
    +	}
    +
    +	/**
    +	 * Retrieve the URI.
    +	 * @return the connection URI when connecting to the broker
    +     */
    +	public String getUri() {
    +		return uri;
    +	}
    +
    +	/**
    +	 * Returns automatic connection recovery interval in milliseconds.
    +	 * @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
    +	 */
    +	public int getNetworkRecoveryInterval() {
    +		return networkRecoveryInterval;
    +	}
    +
    +	/**
    +	 * Returns true if automatic connection recovery is enabled, false otherwise
    +	 * @return true if automatic connection recovery is enabled, false otherwise
    +	 */
    +	public boolean isAutomaticRecovery() {
    +		return automaticRecovery;
    +	}
    +
    +	/**
    +	 * Returns true if topology recovery is enabled, false otherwise
    +	 * @return true if topology recovery is enabled, false otherwise
    +	 */
    +	public boolean isTopologyRecovery() {
    +		return topologyRecovery;
    +	}
    +
    +	/**
    +	 * Retrieve the connection timeout.
    +	 * @return the connection timeout, in milliseconds; zero for infinite
    +	 */
    +	public int getConnectionTimeout() {
    +		return connectionTimeout;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum channel number
    +	 * @return the initially requested maximum channel number; zero for unlimited
    +	 */
    +	public int getRequestedChannelMax() {
    +		return requestedChannelMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum frame size
    +	 * @return the initially requested maximum frame size, in octets; zero for unlimited
    +	 */
    +	public int getRequestedFrameMax() {
    +		return requestedFrameMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested heartbeat interval.
    +	 * @return the initially requested heartbeat interval, in seconds; zero for none
    +	 */
    +	public int getRequestedHeartbeat() {
    +		return requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @return Connection Factory for RMQ
    +	 * @throws Exception if Malformed URI has been passed
    +     */
    +	public ConnectionFactory getConnectionFactory() throws Exception {
    +		ConnectionFactory factory = new ConnectionFactory();
    +		if (this.uri != null && !this.uri.isEmpty()){
    +			try {
    +				factory.setUri(getUri());
    +			}catch (Exception e){
    +				LOG.error("Failed to parse uri {}", e.getMessage());
    +				throw e;
    +			}
    +		} else {
    +			factory.setHost(getHost());
    +			factory.setPort(getPort());
    +			factory.setVirtualHost(getVirtualHost());
    +			factory.setUsername(getUsername());
    +			factory.setPassword(getPassword());
    +		}
    +
    +		factory.setAutomaticRecoveryEnabled(isAutomaticRecovery());
    +		factory.setConnectionTimeout(getConnectionTimeout());
    +		factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
    +		factory.setRequestedHeartbeat(getRequestedHeartbeat());
    +		factory.setTopologyRecoveryEnabled(isTopologyRecovery());
    +		factory.setRequestedChannelMax(getRequestedChannelMax());
    +		factory.setRequestedFrameMax(getRequestedFrameMax());
    +
    +		return factory;
    +	}
    +
    +	public static class Builder {
    +		/** The default host */
    +		public static final String DEFAULT_HOST = "localhost";
    --- End diff --
    
    I would love to use solution a. but 
    ```java
    private int networkRecoveryInterval  = 5000;
    private boolean automaticRecovery  = false;
    private boolean topologyRecovery    = true;
    ```
    these three are not public in **ConnectionFactory**  so we can have to use the null check for these three. so better i am going with solution b. :)


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

[GitHub] flink pull request #2054: [FLINK-3763] RabbitMQ Source/Sink standardize conn...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/flink/pull/2054


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65252489
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    +     */
    +	private RMQConnectionConfig(String uri, int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(uri, "Uri can not be null");
    +		this.uri = uri;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/** @return the host to use for connections */
    +	public String getHost() {
    +		return host;
    +	}
    +
    +	/** @return the port to use for connections */
    +	public int getPort() {
    +		return port;
    +	}
    +
    +	/**
    +	 * Retrieve the virtual host.
    +	 * @return the virtual host to use when connecting to the broker
    +	 */
    +	public String getVirtualHost() {
    +		return virtualHost;
    +	}
    +
    +	/**
    +	 * Retrieve the user name.
    +	 * @return the AMQP user name to use when connecting to the broker
    +	 */
    +	public String getUsername() {
    +		return username;
    +	}
    +
    +	/**
    +	 * Retrieve the password.
    +	 * @return the password to use when connecting to the broker
    +	 */
    +	public String getPassword() {
    +		return password;
    +	}
    +
    +	/**
    +	 * Retrieve the URI.
    +	 * @return the connection URI when connecting to the broker
    +     */
    +	public String getUri() {
    +		return uri;
    +	}
    +
    +	/**
    +	 * Returns automatic connection recovery interval in milliseconds.
    +	 * @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
    +	 */
    +	public int getNetworkRecoveryInterval() {
    +		return networkRecoveryInterval;
    +	}
    +
    +	/**
    +	 * Returns true if automatic connection recovery is enabled, false otherwise
    +	 * @return true if automatic connection recovery is enabled, false otherwise
    +	 */
    +	public boolean isAutomaticRecovery() {
    +		return automaticRecovery;
    +	}
    +
    +	/**
    +	 * Returns true if topology recovery is enabled, false otherwise
    +	 * @return true if topology recovery is enabled, false otherwise
    +	 */
    +	public boolean isTopologyRecovery() {
    +		return topologyRecovery;
    +	}
    +
    +	/**
    +	 * Retrieve the connection timeout.
    +	 * @return the connection timeout, in milliseconds; zero for infinite
    +	 */
    +	public int getConnectionTimeout() {
    +		return connectionTimeout;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum channel number
    +	 * @return the initially requested maximum channel number; zero for unlimited
    +	 */
    +	public int getRequestedChannelMax() {
    +		return requestedChannelMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum frame size
    +	 * @return the initially requested maximum frame size, in octets; zero for unlimited
    +	 */
    +	public int getRequestedFrameMax() {
    +		return requestedFrameMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested heartbeat interval.
    +	 * @return the initially requested heartbeat interval, in seconds; zero for none
    +	 */
    +	public int getRequestedHeartbeat() {
    +		return requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @return Connection Factory for RMQ
    +	 * @throws Exception if Malformed URI has been passed
    +     */
    +	public ConnectionFactory getConnectionFactory() throws Exception {
    +		ConnectionFactory factory = new ConnectionFactory();
    +		if (this.uri != null && !this.uri.isEmpty()){
    +			try {
    +				factory.setUri(getUri());
    +			}catch (Exception e){
    +				LOG.error("Failed to parse uri {}", e.getMessage());
    +				throw e;
    +			}
    +		} else {
    +			factory.setHost(getHost());
    +			factory.setPort(getPort());
    +			factory.setVirtualHost(getVirtualHost());
    +			factory.setUsername(getUsername());
    +			factory.setPassword(getPassword());
    +		}
    +
    +		factory.setAutomaticRecoveryEnabled(isAutomaticRecovery());
    +		factory.setConnectionTimeout(getConnectionTimeout());
    +		factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
    +		factory.setRequestedHeartbeat(getRequestedHeartbeat());
    +		factory.setTopologyRecoveryEnabled(isTopologyRecovery());
    +		factory.setRequestedChannelMax(getRequestedChannelMax());
    +		factory.setRequestedFrameMax(getRequestedFrameMax());
    +
    +		return factory;
    +	}
    +
    +	public static class Builder {
    +		/** The default host */
    +		public static final String DEFAULT_HOST = "localhost";
    --- End diff --
    
    I assume you got all these default values from the RabbitMQ's `ConnectionFactory`.
    
    The problem is that your code is setting all these default values in the `getConnectionFactory()`  because all the fields are initialized with the default values.
    This can lead to issues when we change the RMQ version, without checking if the defaults have changed.
    I see two solutions:
    a) We use the defaults from RabbitMQs `ConnectionFactory`, since they are public
    b) We change the builder so that we only pass those parameters which were set by the user (this can probably be done easily by initializing them all with `null`)
    
    I think I prefer solution b)


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65253122
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSink.java ---
    @@ -35,24 +36,28 @@
     	private static final Logger LOG = LoggerFactory.getLogger(RMQSink.class);
     
     	private String QUEUE_NAME;
    --- End diff --
    
    I know its not part of the issue's scope, but could you rename this field to `queueName`. Otherwise, the class has a very poor style which makes it hard to read it.


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65250839
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    --- End diff --
    
    It seems that the indentation here is done using tabs and spaces.


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65252614
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    +     */
    +	private RMQConnectionConfig(String uri, int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(uri, "Uri can not be null");
    +		this.uri = uri;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/** @return the host to use for connections */
    +	public String getHost() {
    +		return host;
    +	}
    +
    +	/** @return the port to use for connections */
    +	public int getPort() {
    +		return port;
    +	}
    +
    +	/**
    +	 * Retrieve the virtual host.
    +	 * @return the virtual host to use when connecting to the broker
    +	 */
    +	public String getVirtualHost() {
    +		return virtualHost;
    +	}
    +
    +	/**
    +	 * Retrieve the user name.
    +	 * @return the AMQP user name to use when connecting to the broker
    +	 */
    +	public String getUsername() {
    +		return username;
    +	}
    +
    +	/**
    +	 * Retrieve the password.
    +	 * @return the password to use when connecting to the broker
    +	 */
    +	public String getPassword() {
    +		return password;
    +	}
    +
    +	/**
    +	 * Retrieve the URI.
    +	 * @return the connection URI when connecting to the broker
    +     */
    +	public String getUri() {
    +		return uri;
    +	}
    +
    +	/**
    +	 * Returns automatic connection recovery interval in milliseconds.
    +	 * @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
    +	 */
    +	public int getNetworkRecoveryInterval() {
    +		return networkRecoveryInterval;
    +	}
    +
    +	/**
    +	 * Returns true if automatic connection recovery is enabled, false otherwise
    +	 * @return true if automatic connection recovery is enabled, false otherwise
    +	 */
    +	public boolean isAutomaticRecovery() {
    +		return automaticRecovery;
    +	}
    +
    +	/**
    +	 * Returns true if topology recovery is enabled, false otherwise
    +	 * @return true if topology recovery is enabled, false otherwise
    +	 */
    +	public boolean isTopologyRecovery() {
    +		return topologyRecovery;
    +	}
    +
    +	/**
    +	 * Retrieve the connection timeout.
    +	 * @return the connection timeout, in milliseconds; zero for infinite
    +	 */
    +	public int getConnectionTimeout() {
    +		return connectionTimeout;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum channel number
    +	 * @return the initially requested maximum channel number; zero for unlimited
    +	 */
    +	public int getRequestedChannelMax() {
    +		return requestedChannelMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum frame size
    +	 * @return the initially requested maximum frame size, in octets; zero for unlimited
    +	 */
    +	public int getRequestedFrameMax() {
    +		return requestedFrameMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested heartbeat interval.
    +	 * @return the initially requested heartbeat interval, in seconds; zero for none
    +	 */
    +	public int getRequestedHeartbeat() {
    +		return requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @return Connection Factory for RMQ
    +	 * @throws Exception if Malformed URI has been passed
    +     */
    +	public ConnectionFactory getConnectionFactory() throws Exception {
    +		ConnectionFactory factory = new ConnectionFactory();
    +		if (this.uri != null && !this.uri.isEmpty()){
    +			try {
    +				factory.setUri(getUri());
    +			}catch (Exception e){
    +				LOG.error("Failed to parse uri {}", e.getMessage());
    +				throw e;
    +			}
    +		} else {
    +			factory.setHost(getHost());
    +			factory.setPort(getPort());
    +			factory.setVirtualHost(getVirtualHost());
    +			factory.setUsername(getUsername());
    +			factory.setPassword(getPassword());
    +		}
    +
    +		factory.setAutomaticRecoveryEnabled(isAutomaticRecovery());
    +		factory.setConnectionTimeout(getConnectionTimeout());
    +		factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
    +		factory.setRequestedHeartbeat(getRequestedHeartbeat());
    +		factory.setTopologyRecoveryEnabled(isTopologyRecovery());
    +		factory.setRequestedChannelMax(getRequestedChannelMax());
    +		factory.setRequestedFrameMax(getRequestedFrameMax());
    --- End diff --
    
    Why are you calling all the getters to get the field's values? In the `build()` method below, you are accessing the fields using `this.`.


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65253016
  
    --- Diff: docs/apis/streaming/connectors/rabbitmq.md ---
    @@ -71,23 +71,25 @@ Example:
     <div class="codetabs" markdown="1">
     <div data-lang="java" markdown="1">
     {% highlight java %}
    +RMQConnectionConfig connectionConfig = new RMQConnectionConfig.Builder().build();
    --- End diff --
    
    As I've written below, I would prefer if users would not rely on the fact that "localhost" is the default value here.
    Once the builder has been changed, we would expect the user to call `.setHost("localhost")` here.


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65251121
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    +import com.rabbitmq.client.ConnectionFactory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.Serializable;
    +
    +/**
    + * Connection Configuration for RMQ.
    + * If {@link Builder#setUri(String)} has been set then {@link RMQConnectionConfig#RMQConnectionConfig(String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection or
    + * {@link RMQConnectionConfig#RMQConnectionConfig(String, int, String, String, String, int, boolean, boolean, int, int, int, int)}
    + * will be used for initialize the RMQ connection
    + */
    +public class RMQConnectionConfig implements Serializable {
    +
    +	private static final long serialVersionUID = 1L;
    +
    +	private static final Logger LOG = LoggerFactory.getLogger(RMQConnectionConfig.class);
    +
    +	private String host;
    +	private int port;
    +	private String virtualHost;
    +	private String username;
    +	private String password;
    +	private String uri;
    +
    +	private int networkRecoveryInterval;
    +	private boolean automaticRecovery;
    +	private boolean topologyRecovery;
    +
    +	private int connectionTimeout;
    +	private int requestedChannelMax;
    +	private int requestedFrameMax;
    +	private int requestedHeartbeat;
    +
    +	/**
    +	 *
    +	 * @param host host name
    +	 * @param port port
    +	 * @param virtualHost virtual host
    +	 * @param username username
    +	 * @param password password
    +
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +	 * @param requestedFrameMax requested maximum frame size
    +	 * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if host or virtual host or username or password is null
    +     */
    +	private RMQConnectionConfig(String host, int port, String virtualHost, String username, String password,
    +								int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(host, "host can not be null");
    +		Preconditions.checkNotNull(virtualHost, "virtualHost can not be null");
    +		Preconditions.checkNotNull(username, "username can not be null");
    +		Preconditions.checkNotNull(password, "password can not be null");
    +		this.host = host;
    +		this.port = port;
    +		this.virtualHost = virtualHost;
    +		this.username = username;
    +		this.password = password;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @param uri the connection URI
    +	 * @param networkRecoveryInterval connection recovery interval in milliseconds
    +	 * @param automaticRecovery if automatic connection recovery
    +	 * @param topologyRecovery if topology recovery
    +	 * @param connectionTimeout connection timeout
    +	 * @param requestedChannelMax requested maximum channel number
    +     * @param requestedFrameMax requested maximum frame size
    +     * @param requestedHeartbeat requested heartbeat interval
    +	 * @throws NullPointerException if URI is null
    +     */
    +	private RMQConnectionConfig(String uri, int networkRecoveryInterval, boolean automaticRecovery,
    +								boolean topologyRecovery, int connectionTimeout, int requestedChannelMax, int requestedFrameMax,
    +								int requestedHeartbeat){
    +		Preconditions.checkNotNull(uri, "Uri can not be null");
    +		this.uri = uri;
    +
    +		this.networkRecoveryInterval = networkRecoveryInterval;
    +		this.automaticRecovery = automaticRecovery;
    +		this.topologyRecovery = topologyRecovery;
    +		this.connectionTimeout = connectionTimeout;
    +		this.requestedChannelMax = requestedChannelMax;
    +		this.requestedFrameMax = requestedFrameMax;
    +		this.requestedHeartbeat = requestedHeartbeat;
    +	}
    +
    +	/** @return the host to use for connections */
    +	public String getHost() {
    +		return host;
    +	}
    +
    +	/** @return the port to use for connections */
    +	public int getPort() {
    +		return port;
    +	}
    +
    +	/**
    +	 * Retrieve the virtual host.
    +	 * @return the virtual host to use when connecting to the broker
    +	 */
    +	public String getVirtualHost() {
    +		return virtualHost;
    +	}
    +
    +	/**
    +	 * Retrieve the user name.
    +	 * @return the AMQP user name to use when connecting to the broker
    +	 */
    +	public String getUsername() {
    +		return username;
    +	}
    +
    +	/**
    +	 * Retrieve the password.
    +	 * @return the password to use when connecting to the broker
    +	 */
    +	public String getPassword() {
    +		return password;
    +	}
    +
    +	/**
    +	 * Retrieve the URI.
    +	 * @return the connection URI when connecting to the broker
    +     */
    +	public String getUri() {
    +		return uri;
    +	}
    +
    +	/**
    +	 * Returns automatic connection recovery interval in milliseconds.
    +	 * @return how long will automatic recovery wait before attempting to reconnect, in ms; default is 5000
    +	 */
    +	public int getNetworkRecoveryInterval() {
    +		return networkRecoveryInterval;
    +	}
    +
    +	/**
    +	 * Returns true if automatic connection recovery is enabled, false otherwise
    +	 * @return true if automatic connection recovery is enabled, false otherwise
    +	 */
    +	public boolean isAutomaticRecovery() {
    +		return automaticRecovery;
    +	}
    +
    +	/**
    +	 * Returns true if topology recovery is enabled, false otherwise
    +	 * @return true if topology recovery is enabled, false otherwise
    +	 */
    +	public boolean isTopologyRecovery() {
    +		return topologyRecovery;
    +	}
    +
    +	/**
    +	 * Retrieve the connection timeout.
    +	 * @return the connection timeout, in milliseconds; zero for infinite
    +	 */
    +	public int getConnectionTimeout() {
    +		return connectionTimeout;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum channel number
    +	 * @return the initially requested maximum channel number; zero for unlimited
    +	 */
    +	public int getRequestedChannelMax() {
    +		return requestedChannelMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested maximum frame size
    +	 * @return the initially requested maximum frame size, in octets; zero for unlimited
    +	 */
    +	public int getRequestedFrameMax() {
    +		return requestedFrameMax;
    +	}
    +
    +	/**
    +	 * Retrieve the requested heartbeat interval.
    +	 * @return the initially requested heartbeat interval, in seconds; zero for none
    +	 */
    +	public int getRequestedHeartbeat() {
    +		return requestedHeartbeat;
    +	}
    +
    +	/**
    +	 *
    +	 * @return Connection Factory for RMQ
    +	 * @throws Exception if Malformed URI has been passed
    +     */
    +	public ConnectionFactory getConnectionFactory() throws Exception {
    +		ConnectionFactory factory = new ConnectionFactory();
    +		if (this.uri != null && !this.uri.isEmpty()){
    +			try {
    +				factory.setUri(getUri());
    +			}catch (Exception e){
    +				LOG.error("Failed to parse uri {}", e.getMessage());
    +				throw e;
    +			}
    +		} else {
    +			factory.setHost(getHost());
    +			factory.setPort(getPort());
    +			factory.setVirtualHost(getVirtualHost());
    +			factory.setUsername(getUsername());
    +			factory.setPassword(getPassword());
    +		}
    +
    +		factory.setAutomaticRecoveryEnabled(isAutomaticRecovery());
    +		factory.setConnectionTimeout(getConnectionTimeout());
    +		factory.setNetworkRecoveryInterval(getNetworkRecoveryInterval());
    +		factory.setRequestedHeartbeat(getRequestedHeartbeat());
    +		factory.setTopologyRecoveryEnabled(isTopologyRecovery());
    +		factory.setRequestedChannelMax(getRequestedChannelMax());
    +		factory.setRequestedFrameMax(getRequestedFrameMax());
    +
    +		return factory;
    +	}
    +
    +	public static class Builder {
    +		/** The default host */
    +		public static final String DEFAULT_HOST = "localhost";
    +
    +		/** 'Use the default port' port */
    +		public static final int USE_DEFAULT_PORT = -1;
    +
    +		/** Default virtual host */
    +		public static final String DEFAULT_VHOST = "/";
    +
    +		/** Default user name */
    +		public static final String DEFAULT_USER = "guest";
    +
    +		/** Default password */
    +		public static final String DEFAULT_PASS = "guest";
    +
    +		/** The default connection timeout;
    +		 *  zero means wait indefinitely */
    +		public static final int DEFAULT_CONNECTION_TIMEOUT = 0;
    +
    +		/** Default maximum channel number;
    +		 *  zero for unlimited */
    +		public static final int DEFAULT_CHANNEL_MAX = 0;
    +
    +		/** Default maximum frame size;
    +		 *  zero means no limit */
    +		public static final int DEFAULT_FRAME_MAX = 0;
    +
    +		/** Default heart-beat interval;
    +		 *  zero means no heart-beats */
    +		public static final int DEFAULT_HEARTBEAT = 0;
    +
    +		private String host 		=  DEFAULT_HOST;
    +		private int port 			=  USE_DEFAULT_PORT;
    +		private String virtualHost  =  DEFAULT_VHOST;
    +		private String username     =  DEFAULT_USER;
    +		private String password     =  DEFAULT_PASS;
    +
    +		private int networkRecoveryInterval          = 5000;
    +		private boolean automaticRecovery            = false;
    +		private boolean topologyRecovery             = true;
    +
    +		private int connectionTimeout                = DEFAULT_CONNECTION_TIMEOUT;
    +		private int requestedChannelMax              = DEFAULT_CHANNEL_MAX;
    +		private int requestedFrameMax                = DEFAULT_FRAME_MAX;
    +		private int requestedHeartbeat               = DEFAULT_HEARTBEAT;
    --- End diff --
    
    This formatting is not consistent with the rest of the Flink codebase. Can you just use a space before and after the equals sign?


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65253337
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSink.java ---
    @@ -35,24 +36,28 @@
     	private static final Logger LOG = LoggerFactory.getLogger(RMQSink.class);
     
     	private String QUEUE_NAME;
    -	private String HOST_NAME;
    +	private RMQConnectionConfig rmqConnectionConfig;
     	private transient ConnectionFactory factory;
     	private transient Connection connection;
     	private transient Channel channel;
     	private SerializationSchema<IN> schema;
     
    -	public RMQSink(String HOST_NAME, String QUEUE_NAME, SerializationSchema<IN> schema) {
    -		this.HOST_NAME = HOST_NAME;
    +	/**
    +	 * @param rmqConnectionConfig The RabbiMQ connection configuration {@link RMQConnectionConfig}.
    +	 * @param QUEUE_NAME The queue to publish messages to.
    +	 * @param schema A {@link SerializationSchema} for turning the Java objects received into bytes
    +     */
    +	public RMQSink(RMQConnectionConfig rmqConnectionConfig, String QUEUE_NAME, SerializationSchema<IN> schema) {
    +		this.rmqConnectionConfig = rmqConnectionConfig;
     		this.QUEUE_NAME = QUEUE_NAME;
     		this.schema = schema;
     	}
     
     	/**
     	 * Initializes the connection to RMQ.
     	 */
    -	public void initializeConnection() {
    -		factory = new ConnectionFactory();
    -		factory.setHost(HOST_NAME);
    +	public void initializeConnection() throws Exception {
    +		factory = rmqConnectionConfig.getConnectionFactory();
    --- End diff --
    
    Another comment which is something that has been like this before: Could you remove the initializeConnection() method and move all its content into the open() method.
    That reduces unnecessary boilerplate. 
    
    Thank you ;)


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2054#discussion_r65250708
  
    --- Diff: flink-streaming-connectors/flink-connector-rabbitmq/src/main/java/org/apache/flink/streaming/connectors/rabbitmq/common/RMQConnectionConfig.java ---
    @@ -0,0 +1,455 @@
    +/*
    + * 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.flink.streaming.connectors.rabbitmq.common;
    +
    +import com.google.common.base.Preconditions;
    --- End diff --
    
    Could you use Flink's own `Preconditions` class in org.apache.flink.util?
    We are trying to get rid of guava in the long run.


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

[GitHub] flink pull request: [FLINK-3763] RabbitMQ Source/Sink standardize connection...

Posted by rmetzger <gi...@git.apache.org>.
Github user rmetzger commented on the pull request:

    https://github.com/apache/flink/pull/2054
  
    Thank you for your contribution.
    There are still some open issues that need addressing before we can merge this.


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