本文整理匯總了Golang中github.com/mozilla-services/heka/message.Message.SetPid方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.SetPid方法的具體用法?Golang Message.SetPid怎麽用?Golang Message.SetPid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mozilla-services/heka/message.Message
的用法示例。
在下文中一共展示了Message.SetPid方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PopulateMessage
// Applies this message template's values to the provided message object,
// interpolating the provided substitutions into the values in the process.
func (mt MessageTemplate) PopulateMessage(msg *message.Message, subs map[string]string) error {
var val string
for field, rawVal := range mt {
val = InterpolateString(rawVal, subs)
switch field {
case "Logger":
msg.SetLogger(val)
case "Type":
msg.SetType(val)
case "Payload":
msg.SetPayload(val)
case "Hostname":
msg.SetHostname(val)
case "Pid":
pid, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return err
}
msg.SetPid(int32(pid))
case "Uuid":
msg.SetUuid([]byte(val))
default:
fi := strings.SplitN(field, "|", 2)
if len(fi) < 2 {
fi = append(fi, "")
}
f, err := message.NewField(fi[0], val, fi[1])
msg.AddField(f)
if err != nil {
return err
}
}
}
return nil
}
示例2: PopulateMessage
// Applies this message template's values to the provided message object,
// interpolating the provided substitutions into the values in the process.
func (mt MessageTemplate) PopulateMessage(msg *message.Message, subs map[string]string) error {
var val string
for field, rawVal := range mt {
if subs == nil {
val = rawVal
} else {
val = InterpolateString(rawVal, subs)
}
switch field {
case "Logger":
msg.SetLogger(val)
case "Type":
msg.SetType(val)
case "Payload":
msg.SetPayload(val)
case "Hostname":
msg.SetHostname(val)
case "Pid":
intPart := strings.Split(val, ".")[0]
pid, err := strconv.ParseInt(intPart, 10, 32)
if err != nil {
return err
}
msg.SetPid(int32(pid))
case "Severity":
severity, err := strconv.ParseInt(val, 10, 32)
if err != nil {
return err
}
msg.SetSeverity(int32(severity))
case "Uuid":
if len(val) == message.UUID_SIZE {
msg.SetUuid([]byte(val))
} else {
if uuidBytes := uuid.Parse(val); uuidBytes == nil {
return errors.New("Invalid UUID string.")
} else {
msg.SetUuid(uuidBytes)
}
}
default:
fi := strings.SplitN(field, "|", 2)
if len(fi) < 2 {
fi = append(fi, "")
}
f, err := message.NewField(fi[0], val, fi[1])
msg.AddField(f)
if err != nil {
return err
}
}
}
return nil
}
示例3: copyMessageHeaders
func copyMessageHeaders(dst *message.Message, src *message.Message) {
if src == nil || dst == nil || src == dst {
return
}
if cap(src.Uuid) > 0 {
dst.SetUuid(src.Uuid)
} else {
dst.Uuid = nil
}
if src.Timestamp != nil {
dst.SetTimestamp(*src.Timestamp)
} else {
dst.Timestamp = nil
}
if src.Type != nil {
dst.SetType(*src.Type)
} else {
dst.Type = nil
}
if src.Logger != nil {
dst.SetLogger(*src.Logger)
} else {
dst.Logger = nil
}
if src.Severity != nil {
dst.SetSeverity(*src.Severity)
} else {
dst.Severity = nil
}
if src.Pid != nil {
dst.SetPid(*src.Pid)
} else {
dst.Pid = nil
}
if src.Hostname != nil {
dst.SetHostname(*src.Hostname)
} else {
dst.Hostname = nil
}
}
示例4: AMQPPluginSpec
//.........這裏部分代碼省略.........
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Expect the injected packet
ith.MockInputRunner.EXPECT().Inject(gomock.Any())
// Increase the usage since Run decrements it on close
ug.Add(1)
ith.PackSupply <- ith.Pack
go func() {
err := amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
errChan <- err
}()
ith.PackSupply <- ith.Pack
close(streamChan)
err = <-errChan
c.Expect(ith.Pack.Message.GetType(), gs.Equals, "amqp")
c.Expect(ith.Pack.Message.GetPayload(), gs.Equals, "This is a message")
})
c.Specify("consumes a serialized message", func() {
encoder := client.NewProtobufEncoder(nil)
streamChan := make(chan amqp.Delivery, 1)
msg := new(message.Message)
msg.SetUuid(uuid.NewRandom())
msg.SetTimestamp(time.Now().UnixNano())
msg.SetType("logfile")
msg.SetLogger("/a/nice/path")
msg.SetSeverity(int32(0))
msg.SetEnvVersion("0.2")
msg.SetPid(0)
msg.SetPayload("This is a message")
msg.SetHostname("TestHost")
msgBody := make([]byte, 0, 500)
_ = encoder.EncodeMessageStream(msg, &msgBody)
ack := plugins_ts.NewMockAcknowledger(ctrl)
ack.EXPECT().Ack(gomock.Any(), false)
streamChan <- amqp.Delivery{
ContentType: "application/hekad",
Body: msgBody,
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Expect the decoded pack
mockDRunner.EXPECT().InChan().Return(ith.DecodeChan)
// Increase the usage since Run decrements it on close
ug.Add(1)
ith.PackSupply <- ith.Pack
go func() {
err := amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
errChan <- err
}()
packRef := <-ith.DecodeChan
c.Expect(ith.Pack, gs.Equals, packRef)
// Ignore leading 5 bytes of encoded message as thats the header
示例5: AMQPPluginSpec
//.........這裏部分代碼省略.........
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Expect the injected packet
ith.MockInputRunner.EXPECT().Inject(gomock.Any())
// Increase the usage since Run decrements it on close
ug.Add(1)
ith.PackSupply <- ith.Pack
go func() {
amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
}()
ith.PackSupply <- ith.Pack
c.Expect(ith.Pack.Message.GetType(), gs.Equals, "amqp")
c.Expect(ith.Pack.Message.GetPayload(), gs.Equals, "This is a message")
close(streamChan)
})
c.Specify("consumes a serialized message", func() {
encoder := client.NewProtobufEncoder(nil)
streamChan := make(chan amqp.Delivery, 1)
msg := new(message.Message)
msg.SetUuid(uuid.NewRandom())
msg.SetTimestamp(time.Now().UnixNano())
msg.SetType("logfile")
msg.SetLogger("/a/nice/path")
msg.SetSeverity(int32(0))
msg.SetEnvVersion("0.2")
msg.SetPid(0)
msg.SetPayload("This is a message")
msg.SetHostname("TestHost")
msgBody := make([]byte, 0, 500)
_ = encoder.EncodeMessageStream(msg, &msgBody)
ack := ts.NewMockAcknowledger(ctrl)
ack.EXPECT().Ack(gomock.Any(), false)
streamChan <- amqp.Delivery{
ContentType: "application/hekad",
Body: msgBody,
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Expect the decoded pack
mockDecoderRunner := ith.Decoders[message.Header_PROTOCOL_BUFFER].(*MockDecoderRunner)
mockDecoderRunner.EXPECT().InChan().Return(ith.DecodeChan)
// Increase the usage since Run decrements it on close
ug.Add(1)
ith.PackSupply <- ith.Pack
go func() {
amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
}()
packRef := <-ith.DecodeChan
c.Expect(ith.Pack, gs.Equals, packRef)
// Ignore leading 5 bytes of encoded message as thats the header
示例6: AMQPPluginSpec
//.........這裏部分代碼省略.........
// Increase the usage since Run decrements it on close.
ug.Add(1)
splitCall := ith.MockSplitterRunner.EXPECT().SplitBytes(gomock.Any(),
nil)
splitCall.Do(func(recd []byte, del Deliverer) {
bytesChan <- recd
})
ith.MockSplitterRunner.EXPECT().UseMsgBytes().Return(false)
ith.MockSplitterRunner.EXPECT().SetPackDecorator(gomock.Any())
go func() {
err := amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
errChan <- err
}()
msgBytes := <-bytesChan
c.Expect(string(msgBytes), gs.Equals, "This is a message")
close(streamChan)
err = <-errChan
})
c.Specify("consumes a protobuf encoded message", func() {
encoder := client.NewProtobufEncoder(nil)
streamChan := make(chan amqp.Delivery, 1)
msg := new(message.Message)
msg.SetUuid(uuid.NewRandom())
msg.SetTimestamp(time.Now().UnixNano())
msg.SetType("logfile")
msg.SetLogger("/a/nice/path")
msg.SetSeverity(int32(0))
msg.SetEnvVersion("0.2")
msg.SetPid(0)
msg.SetPayload("This is a message")
msg.SetHostname("TestHost")
msgBody := make([]byte, 0, 500)
_ = encoder.EncodeMessageStream(msg, &msgBody)
ack := plugins_ts.NewMockAcknowledger(ctrl)
ack.EXPECT().Ack(gomock.Any(), false)
streamChan <- amqp.Delivery{
ContentType: "application/hekad",
Body: msgBody,
Timestamp: time.Now(),
Acknowledger: ack,
}
mch.EXPECT().Consume("", "", false, false, false, false,
gomock.Any()).Return(streamChan, nil)
// Increase the usage since Run decrements it on close.
ug.Add(1)
splitCall := ith.MockSplitterRunner.EXPECT().SplitBytes(gomock.Any(),
nil)
splitCall.Do(func(recd []byte, del Deliverer) {
bytesChan <- recd
})
ith.MockSplitterRunner.EXPECT().UseMsgBytes().Return(true)
go func() {
err := amqpInput.Run(ith.MockInputRunner, ith.MockHelper)
errChan <- err
}()