當前位置: 首頁>>代碼示例>>Golang>>正文


Golang core.Message類代碼示例

本文整理匯總了Golang中github.com/trivago/gollum/core.Message的典型用法代碼示例。如果您正苦於以下問題:Golang Message類的具體用法?Golang Message怎麽用?Golang Message使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Message類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: routeToOrigin

func (prod *Spooling) routeToOrigin(msg core.Message) {
	msg.Route(msg.PrevStreamID)

	if spool, exists := prod.outfile[msg.PrevStreamID]; exists {
		spool.countRead()
	}
}
開發者ID:pombredanne,項目名稱:gollum-1,代碼行數:7,代碼來源:spooling.go

示例2: storeSortedSet

func (prod *Redis) storeSortedSet(msg core.Message) {
	value, _ := prod.format.Format(msg)
	var scoreValue []byte
	if prod.fieldFromParsed {
		scoreMsg := msg
		scoreMsg.Data = value
		scoreValue, _ = prod.fieldFormat.Format(scoreMsg)
	} else {
		scoreValue, _ = prod.fieldFormat.Format(msg)
	}

	score, err := strconv.ParseFloat(string(scoreValue), 64)
	if err != nil {
		Log.Error.Print("Redis: ", err)
		return // ### return, no valid score ###
	}

	result := prod.client.ZAdd(prod.key, redis.Z{
		Score:  score,
		Member: string(value),
	})

	if result.Err() != nil {
		Log.Error.Print("Redis: ", result.Err())
		msg.Drop(prod.GetTimeout())
	}
}
開發者ID:oopcode,項目名稱:gollum,代碼行數:27,代碼來源:redis.go

示例3: storeString

func (prod *Redis) storeString(msg core.Message) {
	value, _ := prod.ProducerBase.Format(msg)

	result := prod.client.Set(prod.key, string(value))
	if result.Err() != nil {
		Log.Error.Print("Redis: ", result.Err())
		msg.Drop(prod.GetTimeout())
	}
}
開發者ID:oopcode,項目名稱:gollum,代碼行數:9,代碼來源:redis.go

示例4: writeMessage

func (prod *File) writeMessage(msg core.Message) {
	msg.Data, msg.StreamID = prod.ProducerBase.Format(msg)
	state, err := prod.getFileState(msg.StreamID, false)
	if err != nil {
		Log.Error.Print("File log error:", err)
		msg.Drop(time.Duration(0))
		return // ### return, dropped ###
	}

	if !state.batch.Append(msg) {
		state.writeBatch()
		state.batch.Append(msg)
	}
}
開發者ID:oopcode,項目名稱:gollum,代碼行數:14,代碼來源:file.go

示例5: routeMessage

func (stream *Route) routeMessage(msg core.Message) {
	for i := 0; i < len(stream.routes); i++ {
		target := stream.routes[i]

		// Stream might require late binding
		if target.stream == nil {
			if core.StreamRegistry.WildcardProducersExist() {
				target.stream = core.StreamRegistry.GetStreamOrFallback(target.id)
			} else if target.stream = core.StreamRegistry.GetStream(target.id); target.stream == nil {
				// Remove without preserving order allows us to continue iterating
				lastIdx := len(stream.routes) - 1
				stream.routes[i] = stream.routes[lastIdx]
				stream.routes = stream.routes[:lastIdx]
				i--
				continue // ### continue, no route ###
			}
		}

		if target.id == stream.GetBoundStreamID() {
			stream.StreamBase.Route(msg, stream.GetBoundStreamID())
		} else {
			msg := msg // copy to allow streamId changes and multiple routes
			msg.StreamID = target.id
			target.stream.Enqueue(msg)
		}
	}
}
開發者ID:pombredanne,項目名稱:gollum-1,代碼行數:27,代碼來源:route.go

示例6: storeHash

func (prod *Redis) storeHash(msg core.Message) {
	value, _ := prod.format.Format(msg)
	var field []byte
	if prod.fieldFromParsed {
		fieldMsg := msg
		fieldMsg.Data = value
		field, _ = prod.fieldFormat.Format(fieldMsg)
	} else {
		field, _ = prod.fieldFormat.Format(msg)
	}

	result := prod.client.HSet(prod.key, string(field), string(value))
	if result.Err() != nil {
		Log.Error.Print("Redis: ", result.Err())
		msg.Drop(prod.GetTimeout())
	}
}
開發者ID:oopcode,項目名稱:gollum,代碼行數:17,代碼來源:redis.go

示例7: Format

// Format prepends the sequence number of the message (followed by ":") to the
// message.
func (format *Serialize) Format(msg core.Message) ([]byte, core.MessageStreamID) {
	msg.Data, msg.StreamID = format.base.Format(msg)
	data, err := msg.Serialize()
	if err != nil {
		Log.Error.Print("Serialize: ", err)
		return msg.Data, msg.StreamID
	}

	if !format.encode {
		return data, msg.StreamID // ### return, raw data ###
	}

	encodedSize := base64.StdEncoding.EncodedLen(len(data))
	encoded := make([]byte, encodedSize+1)
	base64.StdEncoding.Encode(encoded, data)
	encoded[encodedSize] = '\n'

	return encoded, msg.StreamID
}
開發者ID:pombredanne,項目名稱:gollum-1,代碼行數:21,代碼來源:serialize.go

示例8: route

func (cons *LoopBack) route(msg core.Message) {
	if streams, routeExists := cons.routes[msg.StreamID]; routeExists {
		for targetID, targetStream := range streams {
			msg.StreamID = targetID
			targetStream.Enqueue(msg)
		}
	} else {
		// Extend the cache
		targetStream := cons.addRoute(msg.StreamID, msg.StreamID)
		targetStream.Enqueue(msg)
	}
}
開發者ID:oopcode,項目名稱:gollum,代碼行數:12,代碼來源:loopback.go


注:本文中的github.com/trivago/gollum/core.Message類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。