コード例 #1
0
func (group *GroupedSinks) RegisterFirehoseSink(in chan<- *events.Envelope, sink sinks.Sink) bool {
	group.Lock()
	defer group.Unlock()

	subscriptionId := sink.AppID()
	if subscriptionId == "" {
		return false
	}

	fgroup := group.firehoses[subscriptionId]
	if fgroup == nil {
		group.firehoses[subscriptionId] = firehose_group.NewFirehoseGroup()
		fgroup = group.firehoses[subscriptionId]
	}

	return fgroup.AddSink(sink, in)
}
コード例 #2
0
func (f *fakeSink) GetInstrumentationMetric() sinks.Metric {
	return sinks.Metric{}
}

func (f *fakeSink) UpdateDroppedMessageCount(messageCount int64) {}

var _ = Describe("FirehoseGroup", func() {
	It("sends message to all registered sinks", func() {
		receiveChan1 := make(chan *events.Envelope, 10)
		receiveChan2 := make(chan *events.Envelope, 10)

		sink1 := fakeSink{appId: "firehose-a", sinkId: "sink-a"}
		sink2 := fakeSink{appId: "firehose-a", sinkId: "sink-b"}

		group := firehose_group.NewFirehoseGroup()

		group.AddSink(&sink1, receiveChan1)
		group.AddSink(&sink2, receiveChan2)

		msg, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, "test message", "234", "App"), "origin")
		group.BroadcastMessage(msg)

		var nextChannelToReceive chan *events.Envelope
		var rmsg *events.Envelope
		select {
		case rmsg = <-receiveChan1:
			nextChannelToReceive = receiveChan2
		case rmsg = <-receiveChan2:
			nextChannelToReceive = receiveChan1
		}