Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rabbitmq close issue, add automatic recovery #133

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,10 @@ from [RabbitMQ](https://www.rabbitmq.com/).

## Requirements

This library requires Spark 2.0+, Scala 2.11+, RabbitMQ 3.5+
This library was updated to work with Spark 2.3+ and sbt instead of maven.

## Using the library

There are two ways of using RabbitMQ-Receiver library:

The first one is to add the next dependency in your pom.xml:

```
<dependency>
<groupId>com.stratio.receiver</groupId>
<artifactId>spark-rabbitmq</artifactId>
<version>LATEST</version>
</dependency>
```

The other one is to clone the full repository and build the project:

```
git clone https://github.com/Stratio/spark-rabbitmq.git
mvn clean install
```
Create assembly with sbt and import into your project

This library includes two implementations for consuming messages from RabbitMQ with Spark Streaming:

Expand All @@ -42,8 +24,7 @@ This library includes two implementations for consuming messages from RabbitMQ w

### Build

`mvn clean package`

sbt assembly

### Distributed Approach

Expand Down
15 changes: 15 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name := "spark-rabbitmq"

version := "0.1"

scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
"org.apache.hadoop" % "hadoop-mapreduce-client-core" % "2.7.4" % "provided",
"org.apache.spark" %% "spark-core" % "2.3.2" % "provided",
"org.apache.spark" %% "spark-sql" % "2.3.2" % "provided",
"org.apache.spark" %% "spark-streaming" % "2.3.2" % "provided",
"com.softwaremill.sttp" %% "core" % "1.3.8",
"com.softwaremill.sttp" %% "circe" % "1.3.8",
"com.typesafe.akka" %% "akka-actor" % "2.5.18",
"com.rabbitmq" % "amqp-client" % "3.6.6")
275 changes: 0 additions & 275 deletions pom.xml

This file was deleted.

1 change: 1 addition & 0 deletions project/assembly.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.2.7
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ object ConfigParameters {
val AckTypeKey = "ackType"
val FairDispatchKey = "fairDispatch"
val PrefetchCount = "prefetchCount"
val AutomaticRecovery = "automaticRecovery"
val NetworkRecoveryInterval = "networkRecoveryInterval"
val QueueConnectionPropertiesKeys =
List(DurableKey, ExclusiveKey, AutoDeleteKey, AckTypeKey, FairDispatchKey, PrefetchCount)
List(DurableKey, ExclusiveKey, AutoDeleteKey, AckTypeKey, FairDispatchKey, PrefetchCount, AutomaticRecovery,NetworkRecoveryInterval)

/**
* Queue Connection Defaults
Expand All @@ -61,6 +63,8 @@ object ConfigParameters {
val DefaultHost = "localhost"
val DefaultPrefetchCount = 1
val DefaultCodeClose = "320"
val DefaultAutomaticRecovery = true
val DefaultNetworkRecoveryInterval = 10000

/**
* Message Consumed properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ object Consumer extends Logging with ConsumerParamsUtils {

setVirtualHost(params)
setUserPassword(params)
setAutomaticRecoveryEnabled(params)

getChannel(params) match {
case Success(channel) =>
Expand All @@ -225,6 +226,18 @@ object Consumer extends Logging with ConsumerParamsUtils {
}
}

/**
* https://www.rabbitmq.com/api-guide.html#recovery
* @param params
*/
private def setAutomaticRecoveryEnabled(params: Map[String,String]): Unit = {
val recoveryState = params.getOrElse(AutomaticRecovery, DefaultAutomaticRecovery.toString).toBoolean
factory.setAutomaticRecoveryEnabled(recoveryState)
val recoveryInterval = params.getOrElse(NetworkRecoveryInterval, DefaultNetworkRecoveryInterval.toString).toInt
factory.setNetworkRecoveryInterval(recoveryInterval)
}


private def setVirtualHost(params: Map[String, String]): Unit = {
val vHost = params.get(VirtualHostKey)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class RabbitMQRDD[R: ClassTag](
log.info(s"******* Received $numMessages messages by Partition : ${part.index} before close Channel ******")
//Close the scheduler and the channel in the consumer
scheduleProcess.cancel()
consumer.close()
//consumer.close()
}

private def finishIterationAndReturn(): R = {
Expand Down
Loading