本文整理匯總了Golang中doppler/sinkserver/sinkmanager.SinkManager.SendTo方法的典型用法代碼示例。如果您正苦於以下問題:Golang SinkManager.SendTo方法的具體用法?Golang SinkManager.SendTo怎麽用?Golang SinkManager.SendTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類doppler/sinkserver/sinkmanager.SinkManager
的用法示例。
在下文中一共展示了SinkManager.SendTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
It("sends to all known sinks", func() {
sink1 := &channelSink{appId: "myApp",
identifier: "myAppChan1",
done: make(chan struct{}),
}
sink2 := &channelSink{appId: "myApp",
identifier: "myAppChan2",
done: make(chan struct{}),
}
sinkManager.RegisterSink(sink1)
sinkManager.RegisterSink(sink2)
expectedMessageString := "Some Data"
expectedMessage, _ := emitter.Wrap(factories.NewLogMessage(events.LogMessage_OUT, expectedMessageString, "myApp", "App"), "origin")
go sinkManager.SendTo("myApp", expectedMessage)
Eventually(sink1.Received).Should(HaveLen(1))
Eventually(sink2.Received).Should(HaveLen(1))
Expect(sink1.Received()[0]).To(Equal(expectedMessage))
Expect(sink2.Received()[0]).To(Equal(expectedMessage))
})
It("only sends to sinks that match the appID", func(done Done) {
sink1 := &channelSink{appId: "myApp1",
identifier: "myAppChan1",
done: make(chan struct{}),
}
sink2 := &channelSink{appId: "myApp2",
identifier: "myAppChan2",
done: make(chan struct{}),
示例2:
m.RegisterStream(&req, firstSender)
secondSender := newMockGRPCSender()
close(secondSender.SendOutput.Err)
m.RegisterStream(&req, secondSender)
env := &events.Envelope{
EventType: events.Envelope_LogMessage.Enum(),
Origin: proto.String("origin"),
LogMessage: &events.LogMessage{
Message: []byte("I am a MESSAGE!"),
MessageType: events.LogMessage_OUT.Enum(),
Timestamp: proto.Int64(time.Now().UnixNano()),
},
}
m.SendTo("app", env)
payload, err := proto.Marshal(env)
Expect(err).ToNot(HaveOccurred())
expected := &plumbing.Response{
Payload: payload,
}
Eventually(firstSender.SendInput.Resp).Should(BeCalled(
With(expected),
))
Eventually(secondSender.SendInput.Resp).Should(BeCalled(
With(expected),
))
})