本文整理汇总了Golang中github.com/cloudfoundry/yagnats.NATSClient类的典型用法代码示例。如果您正苦于以下问题:Golang NATSClient类的具体用法?Golang NATSClient怎么用?Golang NATSClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NATSClient类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: RemoteAuction
func RemoteAuction(client yagnats.NATSClient, auctionRequest types.AuctionRequest) types.AuctionResult {
guid := util.RandomGuid()
payload, _ := json.Marshal(auctionRequest)
c := make(chan []byte)
client.Subscribe(guid, func(msg *yagnats.Message) {
c <- msg.Payload
})
client.PublishWithReplyTo("diego.auction", guid, payload)
var responsePayload []byte
select {
case responsePayload = <-c:
case <-time.After(time.Minute):
return types.AuctionResult{}
}
var auctionResult types.AuctionResult
err := json.Unmarshal(responsePayload, &auctionResult)
if err != nil {
panic(err)
}
return auctionResult
}
开发者ID:vito,项目名称:auction,代码行数:26,代码来源:auctioneer.go
示例2: handleStaging
func handleStaging(bbs bbs.StagerBBS, natsClient yagnats.NATSClient) {
var task uint64
natsClient.SubscribeWithQueue("stage", "stager", func(msg *yagnats.Message) {
var message stagingMessage
err := json.Unmarshal(msg.Payload, &message)
if err != nil {
logger.Fatal("staging-request.invalid", map[string]interface{}{
"error": err.Error(),
"payload": string(msg.Payload),
})
return
}
for i := 0; i < message.Count; i++ {
guid := atomic.AddUint64(&task, 1)
task := &models.Task{
Guid: fmt.Sprintf("task-%d", guid),
MemoryMB: message.MemoryMB,
ReplyTo: msg.ReplyTo,
}
logger.Info("staging-request.desire", map[string]interface{}{
"task": task,
})
go bbs.DesireTask(task)
}
})
}
开发者ID:vito,项目名称:fake-diego-release,代码行数:33,代码来源:main.go
示例3: NewStartStopListener
func NewStartStopListener(messageBus yagnats.NATSClient, conf *config.Config) *StartStopListener {
listener := &StartStopListener{
messageBus: messageBus,
}
messageBus.Subscribe(conf.SenderNatsStartSubject, func(message *yagnats.Message) {
startMessage, err := models.NewStartMessageFromJSON([]byte(message.Payload))
if err != nil {
panic(err)
}
listener.Starts = append(listener.Starts, startMessage)
})
messageBus.Subscribe(conf.SenderNatsStopSubject, func(message *yagnats.Message) {
stopMessage, err := models.NewStopMessageFromJSON([]byte(message.Payload))
if err != nil {
panic(err)
}
listener.Stops = append(listener.Stops, stopMessage)
})
return listener
}
开发者ID:KeyOfSpectator,项目名称:hm9000,代码行数:23,代码来源:start_stop_listener.go
示例4: Register
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)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:22,代码来源:component.go
示例5: Register
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
}
开发者ID:KeyOfSpectator,项目名称:gorouter,代码行数:23,代码来源:component.go
示例6: init
"time"
)
var guids []string
var natsAddrs []string
var numReps int
var repResources int
var rules types.AuctionRules
var timeout time.Duration
var auctioneerMode string
// plumbing
var natsClient yagnats.NATSClient
var client types.TestRepPoolClient
var communicator types.AuctionCommunicator
func init() {
flag.StringVar(&auctioneerMode, "auctioneerMode", "inprocess", "one of inprocess, remote")
flag.IntVar(&(auctioneer.DefaultRules.MaxRounds), "maxRounds", auctioneer.DefaultRules.MaxRounds, "the maximum number of rounds per auction")
flag.IntVar(&(auctioneer.DefaultRules.MaxBiddingPool), "maxBiddingPool", auctioneer.DefaultRules.MaxBiddingPool, "the maximum number of participants in the pool")
flag.IntVar(&(auctioneer.DefaultRules.MaxConcurrent), "maxConcurrent", auctioneer.DefaultRules.MaxConcurrent, "the maximum number of concurrent auctions to run")
flag.BoolVar(&(auctioneer.DefaultRules.RepickEveryRound), "repickEveryRound", auctioneer.DefaultRules.RepickEveryRound, "whether to repick every round")
}
func TestAuction(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Auction Suite")
开发者ID:vito,项目名称:auction,代码行数:31,代码来源:ketchup_suite_test.go
示例7: runSimulation
func runSimulation(natsClient yagnats.NATSClient) {
simulationLock = &sync.Mutex{}
simulationWait = &sync.WaitGroup{}
taskTracker = map[string]*taskData{}
msg := stagingMessage{
Count: nTasks,
MemoryMB: taskMemory,
}
payload, err := json.Marshal(msg)
if err != nil {
panic(err)
}
t := time.Now()
logger.Info("simulation.start", nTasks)
simulationWait.Add(nTasks)
_, err = natsClient.Subscribe("info.stager.*.staging-request.desire", func(msg *yagnats.Message) {
var desiredLog struct {
Timestamp time.Time `json:"_timestamp"`
Task models.Task `json:"task"`
}
err := json.Unmarshal(msg.Payload, &desiredLog)
if err != nil {
panic(err)
}
registerDesired(desiredLog.Task.Guid, desiredLog.Timestamp)
})
_, err = natsClient.Subscribe("error.>", func(msg *yagnats.Message) {
var errorLog struct {
Timestamp time.Time `json:"_timestamp"`
Error string `json:"error"`
}
err := json.Unmarshal(msg.Payload, &errorLog)
if err != nil {
panic(err)
}
registerError(msg.Subject+": "+errorLog.Error, errorLog.Timestamp)
})
_, err = natsClient.Subscribe("fatal.>", func(msg *yagnats.Message) {
var errorLog struct {
Timestamp time.Time `json:"_timestamp"`
Error string `json:"error"`
}
err := json.Unmarshal(msg.Payload, &errorLog)
if err != nil {
panic(err)
}
registerError(msg.Subject+": "+errorLog.Error, errorLog.Timestamp)
})
executorIndexes := map[string]int{}
_, err = natsClient.Subscribe("completed-task", func(msg *yagnats.Message) {
defer func() {
e := recover()
if e != nil {
logger.Error("RECOVERED PANIC:", e)
}
}()
var task *models.Task
err := json.Unmarshal(msg.Payload, &task)
if err != nil {
panic(err)
}
simulationLock.Lock()
index, ok := executorIndexes[task.ExecutorID]
if !ok {
index = len(executorIndexes) + 1
executorIndexes[task.ExecutorID] = index
}
data, ok := taskTracker[task.Guid]
if !ok {
logger.Error("uknown.runonce.completed", task.Guid, "executor", task.ExecutorID)
simulationLock.Unlock()
return
}
data.CompletionTime = float64(time.Now().UnixNano()) / 1e9
logger.Info("runonce.completed", task.Guid, "executor", task.ExecutorID, "duration", data.CompletionTime-data.DesiredTime)
data.ExecutorIndex = index
data.NumCompletions++
//.........这里部分代码省略.........
开发者ID:vito,项目名称:fake-diego-release,代码行数:101,代码来源:simulation.go
注:本文中的github.com/cloudfoundry/yagnats.NATSClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论