Esempio n. 1
0
func Register(c *VcapComponent, mbusClient yagnats.NATSClient) {
	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)
}
Esempio n. 2
0
func (c *VcapComponent) Register(mbusClient yagnats.NATSClient) error {
	mbusClient.Subscribe("vcap.component.discover", func(msg *yagnats.Message) {
		c.Uptime = c.StartTime.Elapsed()
		b, e := json.Marshal(c)
		if e != nil {
			log.Warnf(e.Error())
			return
		}

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

	b, e := json.Marshal(c)
	if e != nil {
		log.Error(e.Error())
		return e
	}

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

	log.Infof("Component %s registered successfully", c.Type)
	return nil
}