从ServerHealthKafka或ServerHealthSap类型接收消息

时间:2019-07-13 19:00:54

标签: scala akka akka-typed

我具有以下类型定义:

function select <T, K extends keyof T> (array: T[], selectKey: K): T[K][]
function select <T, U> (array: T[], selectFn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[]
function select <T, U, K extends keyof T> (array: T[], selectKeyOrFn: K | ((value: T, index: number, array: T[]) => U), thisArg?: unknown): T[K][] | U[] {
  return typeof selectKeyOrFn === 'function'
    ? array.map(selectKeyOrFn, thisArg)
    : array.map(value => value[selectKeyOrFn]);
}

select(['foo', 'bar'], 'length');
select(['foo', 'bar'], s => s.length);

,我想创建一个接受object ServerMonitoring { sealed trait ServerHealthKafka case object KafkaInactiveConfirmed extends ServerHealthKafka case object KafkaActiveConfirmed extends ServerHealthKafka sealed trait ServerHealthSap case object SapInactiveConfirmed extends ServerHealthSap case object SapActiveConfirmed extends ServerHealthSap } ServerHealthKafka的演员。

我已经开始创建,但是我不知道如何继续:

ServerHealthSap

我必须在这里使用消息适配器吗?

1 个答案:

答案 0 :(得分:1)

Behavior采用一种消息类型,因此您需要为所有消息定义一个公用的trait

sealed trait ServerHealthEvent
sealed trait ServerHealthKafka extends ServerHealthEvent
sealed trait ServerHealthSap extends ServerHealthEvent