Beispiel #1
0
func Register(c *VcapComponent, mbusClient *yagnats.Client) {
	mbusClient.Subscribe("vcap.component.discover", func(msg *yagnats.Message) {
		Component.Uptime = Component.Start.Elapsed()
		b, e := json.Marshal(Component)
		if e != nil {
			log.Warnf(e.Error())
			return
		}

		mbusClient.Publish(msg.ReplyTo, b)
	})

	b, e := json.Marshal(Component)
	if e != nil {
		log.Fatal(e.Error())
		panic("Component's information should be correct")
	}

	mbusClient.Publish("vcap.component.announce", b)

	log.Infof("Component %s registered successfully", Component.Type)
}
	AfterEach(func() {
		if natsRunner != nil {
			natsRunner.Stop()
		}

		if router != nil {
			router.Stop()
		}
	})

	Context("NATS", func() {
		It("RouterGreets", func() {
			response := make(chan []byte)

			mbusClient.Subscribe("router.greet.test.response", func(msg *yagnats.Message) {
				response <- msg.Payload
			})

			mbusClient.PublishWithReplyTo("router.greet", "router.greet.test.response", []byte{})

			var msg []byte
			Eventually(response, 1).Should(Receive(&msg))
			Ω(string(msg)).To(MatchRegexp(".*\"minimumRegisterIntervalInSeconds\":5.*"))
		})

		It("discovers", func() {
			// Test if router responses to discover message
			sig := make(chan vcap.VcapComponent)

			// Since the form of uptime is xxd:xxh:xxm:xxs, we should make
			// sure that router has run at least for one second