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

Getting RabbitMQ Message Delivery Tag #118

Open
mantovani opened this issue Oct 31, 2017 · 4 comments
Open

Getting RabbitMQ Message Delivery Tag #118

mantovani opened this issue Oct 31, 2017 · 4 comments

Comments

@mantovani
Copy link

https://stackoverflow.com/questions/47026864/getting-rabbitmq-message-delivery-tag-stratio-spark-rabbitmq

@mantovani
Copy link
Author

mantovani commented Oct 31, 2017 via email

@kaveh-hariri
Copy link

kaveh-hariri commented Oct 31, 2017

I haven't tested this out, but it would be s omething like this --except change "body" with "deliveryTag"

val ssc = new StreamingContext(spark.sparkContext, Seconds(window))

import scala.collection.JavaConverters._
val stream = RabbitMQUtils.createDistributedStream[Map[String,Any]](ssc,distributedKey,rabbitMQParams,
  (rawMessage: Delivery) =>
    Map(
      "body" -> new Predef.String(rawMessage.getBody),
      "exchange" -> rawMessage.getEnvelope.getExchange,
      "routingKey" -> rawMessage.getEnvelope.getRoutingKey,
      "deliveryTag" -> rawMessage.getEnvelope.getDeliveryTag
    ) ++ {
      //Avoid null pointer Exception
      Option(rawMessage.getProperties.getHeaders) match {
        case Some(headers) => Map("headers" -> headers.asScala)
        case None => Map.empty[String, Any]
      }
    })
stream.start()
  stream.foreachRDD(rdd => { 
  new AvroIngest[v001.asset]().transformAvro(rdd.map(_.get("body").toString),spark,classOf[v001.asset].getName,dp_source,dp_source_type,avroKlass,outPath,Some(List("assetMetadata.data" -> "contextualMetadata")))
  })

ssc

edit: basically,
stream.foreachRDD(rdd => {rdd.map(dt => dosomething(dt.get("deliveryTag")))})

@mantovani
Copy link
Author

mantovani commented Oct 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants