https://github.com/future-architect/fluentdpub
publish only fluentd backend for gocloud.dev/pubsub
https://github.com/future-architect/fluentdpub
Last synced: 8 months ago
JSON representation
publish only fluentd backend for gocloud.dev/pubsub
- Host: GitHub
- URL: https://github.com/future-architect/fluentdpub
- Owner: future-architect
- License: apache-2.0
- Created: 2019-11-05T09:37:08.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T00:22:59.000Z (almost 6 years ago)
- Last Synced: 2025-05-07T21:08:56.207Z (8 months ago)
- Language: Go
- Size: 18.6 KB
- Stars: 0
- Watchers: 13
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fluentdpub - fluentd backend for gocloud.dev's pubsub
[](https://godoc.org/github.com/future-architect/fluentdpub)
`fluentdpub` is a backend for gocloud.dev. It only supports publisher (topic) side.
It supports two style API like gocloud.dev, common URL constructor and Fluentd specific constructor.
## Common URL Constructor
After importing `fluentdpub` package, you can open bia `pubsub.OpenTopic()` function.
`fluentd://` URL only contains tag prefix.
Upstream Fluentd server is specified by ``FLUENTD_UPSTREAM_URL`` env var.
```go
import (
"context"
"gocloud.dev/pubsub"
_ "github.com/future-architect/fluentdpub"
)
// pubsub.OpenTopic creates a *pubsub.Topic from a URL.
// This URL will Dial the Fluentd server at the URL in the environment variable
// FLUENTD_UPSTREAM_URL and send messages with tag "example.tag".
topic, err := pubsub.OpenTopic(ctx, "fluentd://stg.my-app")
if err != nil {
return err
}
err = topic.Send(ctx, &pubsub.Message{
// Fluentd doesn't have main contant named body
// fluentdpub embeds body into metadata.
// Default key of body is "message"
Body: []byte("Hello, World!\n"),
// Metadata is optional and can be nil.
Metadata: map[string]string{
// These are examples of metadata.
// There is nothing special about the key names.
"language": "en",
"importance": "high",
},
})
defer topic.Shutdown(ctx)
```
### Option
URL can have two queries:
- `bodykey` (default: `"message"`):
Message.Body content is stored into `Metadata` of this key.
- `tagkey` (default: `"tag"`):
The Value in this key of `Metadata` is used as tag prefix.
### Tag Name
There three locations you can specify tag.
- `FLUENTD_UPSTREAM_URL`'s path name
- URL's host name
- Metadata's tag value (specified by `tagkey` parameter or `"tag"` by default)
If `FLUENTD_UPSTREAM_URL` is `"tcp://localhost:24224/prod"` URL is `fluentd://my-app` and the message to send contains `"tag"` Metadata with the value `"error"`, log will be sent with `prod.my-app.error` tag. Empty element will be ignored (if `FLUENTD_UPSTREAM_URL` is `"tcp://localhost:24224"`, final tag will be `my-app.error`).
## Fluentd Specific Constructor
The `fluentdpub.OpenTopic` constructor opens a Fluentd subject as a topic. You must first create an *fluent.Fluent to your Fluentd server instance.
```go
import (
"context"
"github.com/future-architect/fluentdpub"
)
// pubsub.OpenTopic creates a *pubsub.Topic from a URL.
// This URL will Dial the Fluentd server at the URL in the environment variable
// FLUENTD_UPSTREAM_URL and send messages with tag "example.tag".
f, err := fluent.New(fluent.Config{
FluentHost: "fluentd.example.com",
})
topic, err := fluentdpub.OpenTopic(f, "prod.myapp", fluentdpub.TopicOptions{})
if err != nil {
return err
}
err = topic.Send(context.Background(), &pubsub.Message{
// Fluentd doesn't have main contant named body
// fluentdpub embeds body into metadata.
// Default key of body is "message"
Body: []byte("Hello, World!\n"),
// Metadata is optional and can be nil.
Metadata: map[string]string{
// These are examples of metadata.
// There is nothing special about the key names.
"language": "en",
"importance": "high",
},
})
```
### Option
TopicOptions has two fields:
- `BodyKey` (default: `"message"`):
Message.Body content is stored into `Metadata` of this key.
- `TagKey` (default: `"tag"`):
The Value in this key of `Metadata` is used as tag prefix.
### Tag Name
There two location you can specify tag.
- URL's host name
- Metadata's tag value (specified by `tagkey` parameter or `"tag"` by default)
If URL is `fluentd://prod.my-app` and the message to send contains `"tag"` Metadata with the value `"error"`, log will be sent with `prod.my-app.error` tag. If one of them is empty, non empty one is used.
## License
Apache 2