akka-测量消费者时间

ux6nzvsh  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(317)

我正在开发一个系统,从jms(消费者)中提取消息并将其推送到kafka主题(生产者)。
既然我的消费者保持活动状态,等待新消息到达jms队列并将其推送到kafka,那么我如何有效地度量每秒可以拉取多少消息呢?
这是我的密码:
我的消费者:

class ActiveMqConsumerActor extends Consumer {

  var startTime: Long = _

  val log = Logging(context.system, this)

  val producerActor = context.actorOf(Props[KafkaProducerActor])

  override def autoAck = false
  override def endpointUri: String = "activemq:KafkaTest"

  override def receive: Receive = LoggingReceive {
    case msg: CamelMessage =>
      val camelMsg = msg.bodyAs[String]
      producerActor ! Message(camelMsg.getBytes)
      sender() ! Ack

    case ex: Exception => sender() ! Failure(ex)

    case _ =>
      log.error("Got a message that I don't understand")
      sender() ! Failure(new Exception("Got a message that I don't understand"))
  }
}

主要内容:

object ActiveMqConsumerTest extends App {

  val system = ActorSystem("KafkaSystem")
  val camel = CamelExtension(system)
  val camelContext = camel.context

  camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://0.0.0.0:61616"))

  val consumer = system.actorOf(Props[ActiveMqConsumerActor].withRouter(FromConfig), "consumer")
  val producer = system.actorOf(Props[KafkaProducerActor].withRouter(FromConfig), "producer")

}

谢谢

f2uvfpb9

f2uvfpb91#

你可以尝试使用“指标”之类的东西。https://dropwizard.github.io/metrics/3.1.0/manual/ 你可以定义精确的指标,包括时间,并在你的参与者内部使用它。

相关问题