Exemplo n.º 1
0
func (c *VcapComponent) Register(mbusClient yagnats.ApceraWrapperNATSClient) error {
	mbusClient.Subscribe("vcap.component.discover", func(msg *nats.Msg) {
		c.Uptime = c.StartTime.Elapsed()
		b, e := json.Marshal(c)
		if e != nil {
			log.Warnf(e.Error())
			return
		}

		mbusClient.Publish(msg.Reply, 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
}
Exemplo n.º 2
0
		Ω(err).ShouldNot(HaveOccurred())
		Ω(strings.Contains(line, "100 Continue")).To(BeTrue())

		var rr *http.Request
		Eventually(rCh).Should(Receive(&rr))
		Ω(rr).ShouldNot(BeNil())
		Ω(rr.Header.Get("Expect")).To(Equal(""))
	})

	It("handles a /routes request", func() {
		var client http.Client
		var req *http.Request
		var resp *http.Response
		var err error

		mbusClient.Publish("router.register", []byte(`{"dea":"dea1","app":"app1","uris":["test.com"],"host":"1.2.3.4","port":1234,"tags":{},"private_instance_id":"private_instance_id"}`))
		time.Sleep(250 * time.Millisecond)

		host := fmt.Sprintf("http://%s:%d/routes", config.Ip, config.Status.Port)

		req, err = http.NewRequest("GET", host, nil)
		req.SetBasicAuth("user", "pass")

		resp, err = client.Do(req)
		Ω(err).ShouldNot(HaveOccurred())
		Ω(resp).ShouldNot(BeNil())
		Ω(resp.StatusCode).To(Equal(200))

		body, err := ioutil.ReadAll(resp.Body)
		defer resp.Body.Close()
		Ω(err).ShouldNot(HaveOccurred())