func ServeAPI(l logger.Logger, conf *config.Config) { store, _ := connectToStore(l, conf) messageBus := connectToMessageBus(l, conf) //no locking necessary for the api server. it's ok to have multiples of these running. //NATS will distribute the requests and ensure that only one api-server handles a given request //because we use a NATS queue. apiServer := apiserver.New( messageBus, store, buildTimeProvider(l), l, ) apiServer.Listen() l.Info(fmt.Sprintf("Serving API over NATS (subject: app.state)")) select {} }
ReplyTo: replyToGuid, }) Ω(messageBus.PublishedMessages[replyToGuid]).Should(HaveLen(1)) return string(messageBus.PublishedMessages[replyToGuid][0].Payload) } BeforeEach(func() { messageBus = fakeyagnats.New() storeAdapter = fakestoreadapter.New() store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger()) timeProvider = &faketimeprovider.FakeTimeProvider{ TimeToProvide: time.Unix(100, 0), } server := apiserver.New(messageBus, store, timeProvider, fakelogger.NewFakeLogger()) server.Listen() }) It("should subscribe on a queue", func() { Ω(messageBus.Subscriptions["app.state"]).ShouldNot(BeEmpty()) subscription := messageBus.Subscriptions["app.state"][0] Ω(subscription.Queue).Should(Equal("hm9000")) }) Context("responding to app.state", func() { Context("when the request is empty", func() { It("should return an empty hash", func() { body := makeRequest("{}") Ω(body).Should(Equal("{}")) })