You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gearpump.apache.org by yanghua <gi...@git.apache.org> on 2017/05/06 04:19:57 UTC

[GitHub] incubator-gearpump pull request #180: [GEARPUMP-303] add a RabbitMQ sink to ...

GitHub user yanghua opened a pull request:

    https://github.com/apache/incubator-gearpump/pull/180

    [GEARPUMP-303] add a RabbitMQ sink to integrate with gearpump

    Be sure to do all of the following to help us incorporate your contribution
    quickly and easily:
    
     - [ ] Make sure the commit message is formatted like:
       `[GEARPUMP-<Jira issue #>] Meaningful description of pull request` 
     - [ ] Make sure tests pass via `sbt clean test`.
     - [ ] Make sure old documentation affected by the pull request has been updated and new documentation added for new functionality. 
    


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

    $ git pull https://github.com/yanghua/incubator-gearpump dev

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

    https://github.com/apache/incubator-gearpump/pull/180.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 #180
    
----

----


---
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] incubator-gearpump pull request #180: [GEARPUMP-303] add a RabbitMQ sink to ...

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

    https://github.com/apache/incubator-gearpump/pull/180#discussion_r115161088
  
    --- Diff: experiments/rabbitmq/src/main/scala/org/apache/gearpump/experimental/rabbitmq/RMQSink.scala ---
    @@ -0,0 +1,182 @@
    +/*
    + * 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.gearpump.experimental.rabbitmq
    +
    +import org.apache.gearpump.Message
    +import org.apache.gearpump.cluster.UserConfig
    +import org.apache.gearpump.streaming.sink.DataSink
    +import org.apache.gearpump.streaming.task.TaskContext
    +import com.rabbitmq.client.Channel
    +import com.rabbitmq.client.{Connection, ConnectionFactory}
    +
    +class RMQSink(userConfig: UserConfig,
    +    val connFactory: (UserConfig) => ConnectionFactory) extends DataSink{
    +
    +  var connectionFactory: ConnectionFactory = connFactory(userConfig)
    +  var connection: Connection = null
    +  var channel: Channel = null
    +  var queueName: String = null
    +
    +  def this(userConfig: UserConfig) = {
    +    this(userConfig, RMQSink.getConnectionFactory)
    +  }
    +
    +  override def open(context: TaskContext): Unit = {
    +    connection = connectionFactory.newConnection
    +    channel = connection.createChannel
    +    if (channel == null) {
    +      throw new RuntimeException("None of RabbitMQ channels are available.")
    +    }
    +    setupQueue()
    +  }
    +
    +  override def write(message: Message): Unit = {
    +    publish(message.msg)
    +  }
    +
    +  override def close(): Unit = {
    +    channel.close()
    +    connection.close()
    +  }
    +
    +  protected def setupQueue(): Unit = {
    +    val queue = RMQSink.getQueueName(userConfig)
    +    if (queue.isEmpty) {
    +      throw new RuntimeException("can not get a RabbitMQ queue name")
    +    }
    +
    +    queueName = queue.get
    +    channel.queueDeclare(queue.get, false, false, false, null)
    +  }
    +
    +  def publish(msg: Any): Unit = {
    +    msg match {
    +      case seq: Seq[Any] =>
    +        seq.foreach(publish)
    +      case str: String => {
    +        channel.basicPublish("", queueName, null, msg.asInstanceOf[String].getBytes)
    +      }
    +      case byteArray: Array[Byte] => {
    +        channel.basicPublish("", queueName, null, byteArray)
    +      }
    +      case _ => {
    --- End diff --
    
    may be we can log some warning 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] incubator-gearpump pull request #180: [GEARPUMP-303] add a RabbitMQ sink to ...

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

    https://github.com/apache/incubator-gearpump/pull/180#discussion_r115162272
  
    --- Diff: experiments/rabbitmq/src/test/scala/org/apache/gearpump/experimental/rabbitmq/RabbitmqSinkSpec.scala ---
    @@ -0,0 +1,53 @@
    +/*
    + * 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.gearpump.experimental.rabbitmq
    +
    +import com.rabbitmq.client.AMQP.Connection
    +import com.rabbitmq.client.ConnectionFactory
    +import org.apache.gearpump.Message
    --- End diff --
    
    And it would be better if there is no unused import.


---
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] incubator-gearpump issue #180: [GEARPUMP-303] add a RabbitMQ sink to integra...

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

    https://github.com/apache/incubator-gearpump/pull/180
  
    +1, merging, thanks @yanghua for contributing! 


---
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] incubator-gearpump issue #180: [GEARPUMP-303] add a RabbitMQ sink to integra...

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

    https://github.com/apache/incubator-gearpump/pull/180
  
    # [Codecov](https://codecov.io/gh/apache/incubator-gearpump/pull/180?src=pr&el=h1) Report
    > Merging [#180](https://codecov.io/gh/apache/incubator-gearpump/pull/180?src=pr&el=desc) into [master](https://codecov.io/gh/apache/incubator-gearpump/commit/9798863753dac06077ce23bef5f451bf7fdca619?src=pr&el=desc) will **decrease** coverage by `0.03%`.
    > The diff coverage is `n/a`.
    
    
    
    ```diff
    @@            Coverage Diff            @@
    ##           master    #180      +/-   ##
    =========================================
    - Coverage   71.63%   71.6%   -0.04%     
    =========================================
      Files         191     191              
      Lines        6086    6086              
      Branches      527     527              
    =========================================
    - Hits         4360    4358       -2     
    - Misses       1726    1728       +2
    ```
    



---
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] incubator-gearpump pull request #180: [GEARPUMP-303] add a RabbitMQ sink to ...

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

    https://github.com/apache/incubator-gearpump/pull/180


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