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/05 08:11:05 UTC

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

GitHub user yanghua opened a pull request:

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

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

    

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

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

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

    https://github.com/apache/incubator-gearpump/pull/178.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 #178
    
----
commit 32b18443d186937b272f8143041ff999fee4ccce
Author: vinoyang <ya...@gmail.com>
Date:   2017-05-05T08:10:17Z

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

----


---
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 #178: [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/178
  
    Hi @yanghua , maybe you can close this one now:)


---
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 #178: [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/178#discussion_r114962293
  
    --- Diff: external/rabbitmq/src/test/scala/org/apache/gearpump/external/rabbitmq/RabbitmqSinkSpec.scala ---
    @@ -0,0 +1,51 @@
    +/*
    + * 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.external.rabbitmq
    +
    +import org.apache.gearpump.Message
    +import org.apache.gearpump.cluster.UserConfig
    +import org.apache.gearpump.streaming.task.TaskContext
    +import org.mockito.Mockito._
    +import org.scalatest.mock.MockitoSugar
    +import org.scalatest.prop.PropertyChecks
    +import org.scalatest.{Matchers, PropSpec}
    +
    +class RabbitmqSinkSpec extends PropSpec with PropertyChecks with Matchers with MockitoSugar {
    +
    +  property("HBaseSink should insert a row successfully") {
    --- End diff --
    
    The assert message is not correct


---
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 #178: [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/178#discussion_r114962623
  
    --- Diff: external/rabbitmq/README.md ---
    @@ -0,0 +1,21 @@
    +# Gearpump RabbitMQ
    +
    +Gearpump integration for [RabbitMQ](https://www.rabbitmq.com/)
    +
    +## Usage
    +
    +The message type that RMQSink is able to handle including:
    +
    + 1. String
    + 2. Array[Byte]
    + 3. Sequence of type 1 and 2
    +
    +Suppose there is a DataSource Task will output above-mentioned messages, you can write a simple application then:
    +
    +```scala
    +val sink = new RMQSink(UserConfig.empty, "$tableName")
    +val sinkProcessor = DataSinkProcessor(sink, "$sinkNum")
    +val split = Processor[DataSource]("$splitNum")
    +val computation = split ~> sinkProcessor
    +val application = StreamApplication("RabbitMQ", Graph(computation), UserConfig.empty)
    +```
    --- End diff --
    
    Probably we also need some configuration doc here, like  `rabbitmq.connection.host ` etc.


---
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 #178: [GEARPUMP-303] add a RabbitMQ sink to ...

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

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


---
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 #178: [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/178#discussion_r114957864
  
    --- Diff: external/rabbitmq/src/main/scala/org/apache/gearpump/external/rabbitmq/RMQSink.scala ---
    @@ -0,0 +1,177 @@
    +/*
    + * 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.external.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) extends DataSink{
    +
    +  var connection: Connection = null
    +  var channel: Channel = null
    +  var queueName: String = null
    +
    +  override def open(context: TaskContext): Unit = {
    +    val factory : ConnectionFactory = RMQSink.getConnectionFactory(userConfig)
    +    connection = factory.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.nonEmpty) {
    +      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@unchecked] => {
    --- End diff --
    
    is `unchecked` annotation needed 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 #178: [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/178#discussion_r114957906
  
    --- Diff: external/rabbitmq/src/main/scala/org/apache/gearpump/external/rabbitmq/RMQSink.scala ---
    @@ -0,0 +1,177 @@
    +/*
    + * 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.external.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) extends DataSink{
    +
    +  var connection: Connection = null
    +  var channel: Channel = null
    +  var queueName: String = null
    +
    +  override def open(context: TaskContext): Unit = {
    +    val factory : ConnectionFactory = RMQSink.getConnectionFactory(userConfig)
    +    connection = factory.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.nonEmpty) {
    --- End diff --
    
    maybe `queue.isEmpty` is better


---
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 #178: [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/178#discussion_r114961959
  
    --- Diff: external/rabbitmq/src/main/scala/org/apache/gearpump/external/rabbitmq/RMQSink.scala ---
    @@ -0,0 +1,177 @@
    +/*
    + * 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.external.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) extends DataSink{
    +
    +  var connection: Connection = null
    +  var channel: Channel = null
    +  var queueName: String = null
    +
    +  override def open(context: TaskContext): Unit = {
    +    val factory : ConnectionFactory = RMQSink.getConnectionFactory(userConfig)
    +    connection = factory.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.nonEmpty) {
    +      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@unchecked] => {
    +        channel.basicPublish("", queueName, null, byteArray)
    +      }
    +      case _ => {
    +
    +      }
    +    }
    +  }
    +
    +}
    +
    +object RMQSink {
    +
    +  val RMQSINK = "rmqsink"
    +  val QUEUE_NAME = "rabbitmq.queue.name"
    +  val SERVER_HOST = "rabbitmq.connection.host"
    +  val SERVER_PORT = "rabbitmq.connection.port"
    +  val CONNECTION_URI = "rabbitmq.connection.uri"
    +  val VIRTUAL_HOST = "rabbitmq.virtualhost"
    +  val AUTH_USERNAME = "rabbitmq.auth.username"
    +  val AUTH_PASSWORD = "rabbitmq.auth.password"
    +  val AUTOMATIC_RECOVERY = "rabbitmq.automatic.recovery"
    +  val CONNECTION_TIMEOUT = "rabbitmq.connection.timeout"
    +  val NETWORK_RECOVERY_INTERVAL = "rabbitmq.network.recovery.interval"
    +  val REQUESTED_HEARTBEAT = "rabbitmq.requested.heartbeat"
    +  val TOPOLOGY_RECOVERY_ENABLED = "rabbitmq.topology.recoveryenabled"
    +  val REQUESTED_CHANNEL_MAX = "rabbitmq.channel.max"
    +  val REQUESTED_FRAME_MAX = "rabbitmq.frame.max"
    +
    +  def getConnectionFactory(userConfig : UserConfig): ConnectionFactory = {
    +    val factory : ConnectionFactory = new ConnectionFactory;
    --- End diff --
    
    don't need comma 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.
---