Documentation
¶
Overview ¶
Example (MetadataChanges) ¶
The README's metadata changes sample, kept here so it compiles.
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package main
import (
"context"
"log"
"time"
"github.com/apache/iggy/foreign/go/client"
"github.com/apache/iggy/foreign/go/client/tcp"
iggcon "github.com/apache/iggy/foreign/go/contracts"
)
// The README's metadata changes sample, kept here so it compiles.
func main() {
ctx := context.Background()
cli, err := client.NewIggyClient(client.WithTcp(tcp.WithServerAddress("127.0.0.1:8090")))
if err != nil {
log.Fatal(err)
}
defer func() { _ = cli.Close() }()
if err := cli.Connect(ctx); err != nil {
log.Fatal(err)
}
if _, err := cli.LoginUser(ctx, "iggy", "iggy"); err != nil {
log.Fatal(err)
}
err = followMetadataChanges(ctx, cli, iggcon.MetadataChangeGroupStreams, iggcon.MetadataChangeGroupTopics)
if err != nil {
log.Fatal(err)
}
}
func followMetadataChanges(ctx context.Context, cli iggcon.Client, groups ...iggcon.MetadataChangeGroup) error {
query := iggcon.NewMetadataChangesQuery(iggcon.EarliestMetadataChangeStart(), groups...)
for {
page, err := cli.GetMetadataChanges(ctx, query)
if err != nil {
return err
}
switch page.Status {
case iggcon.MetadataChangeStatusOk:
for _, record := range page.Records {
log.Printf("op %d %s: %+v", record.Op, record.Kind, record.Body)
}
if page.Next != nil {
query.Start = iggcon.AfterMetadataChangeStart(*page.Next)
}
if !page.HasMore {
time.Sleep(time.Second)
}
case iggcon.MetadataChangeStatusBehind:
time.Sleep(100 * time.Millisecond)
default:
if query.Start, err = rebuildMetadataMirror(ctx, cli, groups); err != nil {
return err
}
}
}
}
// rebuildMetadataMirror pages the current state, then returns the position to
// follow from.
func rebuildMetadataMirror(
ctx context.Context,
cli iggcon.Client,
groups []iggcon.MetadataChangeGroup,
) (iggcon.MetadataChangeStart, error) {
query := iggcon.NewMetadataChangesQuery(iggcon.CurrentMetadataChangeStart(nil), groups...)
for {
page, err := cli.GetMetadataChanges(ctx, query)
if err != nil {
return iggcon.MetadataChangeStart{}, err
}
switch page.Status {
case iggcon.MetadataChangeStatusBehind:
time.Sleep(100 * time.Millisecond)
continue
case iggcon.MetadataChangeStatusExpired, iggcon.MetadataChangeStatusReset:
query.Start = iggcon.CurrentMetadataChangeStart(nil)
continue
}
for _, item := range page.Items {
log.Printf("%s: %+v", item.Group, item.Body)
}
switch {
case page.CurrentPageToken != nil:
query.Start = iggcon.CurrentMetadataChangeStart(page.CurrentPageToken)
case page.Next != nil:
return iggcon.AfterMetadataChangeStart(*page.Next), nil
default:
query.Start = iggcon.CurrentMetadataChangeStart(nil)
}
}
}
Output:
Example (ResourceOptions) ¶
The README's resource options sample, kept here so it compiles.
package main
import (
"context"
"crypto/rand"
"log"
"time"
"github.com/apache/iggy/foreign/go/client"
"github.com/apache/iggy/foreign/go/client/tcp"
iggcon "github.com/apache/iggy/foreign/go/contracts"
)
func main() {
ctx := context.Background()
cli, err := client.NewIggyClient(client.WithTcp(tcp.WithServerAddress("127.0.0.1:8090")))
if err != nil {
log.Fatal(err)
}
defer func() { _ = cli.Close() }()
if err := cli.Connect(ctx); err != nil {
log.Fatal(err)
}
if _, err := cli.LoginUser(ctx, "iggy", "iggy"); err != nil {
log.Fatal(err)
}
key := make([]byte, iggcon.StreamEncryptionKeyLength)
if _, err := rand.Read(key); err != nil {
log.Fatal(err)
}
stream, err := cli.CreateStream(ctx, "orders", &iggcon.StreamOptions{EncryptionKey: key})
if err != nil {
log.Fatal(err)
}
source, _ := stream.EncryptionKeySource()
fingerprint, _ := stream.EncryptionKeyFingerprint()
log.Printf("key source %s, fingerprint %s", source, fingerprint)
streamId, _ := iggcon.NewIdentifier(stream.Id)
partitions := uint32(3)
expiry := iggcon.Duration(time.Hour.Microseconds())
durability := iggcon.DurabilityPersisted
topic, err := cli.CreateTopic(ctx, streamId, "events", &iggcon.TopicOptions{
PartitionsCount: &partitions,
MessageExpiry: &expiry,
Durability: &durability,
})
if err != nil {
log.Fatal(err)
}
topicId, _ := iggcon.NewIdentifier(topic.Id)
size := uint64(10 << 30)
if err := cli.UpdateTopic(ctx, streamId, topicId, iggcon.TopicUpdate{
MaxTopicSize: &size,
Reset: []iggcon.TopicOptionKey{iggcon.TopicOptionMessageExpiry},
}); err != nil {
log.Fatal(err)
}
specs, err := cli.DescribeOptions(ctx, iggcon.OptionsScopeTopic)
if err != nil {
log.Fatal(err)
}
for _, spec := range specs {
log.Printf("%s updatable=%t resettable=%t", spec.Key, spec.Updatable, spec.Resettable)
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewIggyClient ¶
NewIggyClient creates the IggyClient instance without connecting. Call Connect to establish the connection to the server. If no Option is provided, NewIggyClient will create a default TCP client.
func ParseConnectionString ¶ added in v0.10.0
ParseConnectionString parses an Iggy TCP connection string into the TCP client options it describes, so the result can be passed to WithTcp:
client.NewIggyClient(client.WithTcp(opts...))
with opts from client.ParseConnectionString("iggy://iggy:iggy@localhost:8090").
The accepted shape is:
iggy://[username:password@ | personal_access_token@]host:port[?options] iggy+tcp://[username:password@ | personal_access_token@]host:port[?options]
The scheme iggy:// means TCP, the same as the explicit iggy+tcp://. Other iggy+<transport> schemes such as iggy+quic:// are rejected, because the Go SDK implements the TCP transport only, which covers both plain TCP and TLS. Credentials are username:password or a single personal access token before the @; either way auto-login is configured, matching what the Rust and Node SDKs do with a connection string. The host may be a bracketed IPv6 literal, as in [::1]:8090.
Query options follow the grammar the other SDKs share:
tls=true|false enable TLS tls_domain=<name> TLS server name indication (SNI) tls_ca_file=<path> CA certificate file for verification reconnection_retries=<n|unlimited> reconnection_interval=<non-zero duration> reestablish_after=<duration> heartbeat_interval=<non-zero duration> nodelay=true|false
Durations take the units the other SDKs share, from nanos to years, including the hr, hrs, wk, wks, month and µs spellings, with optional fractions and parts run together or spaced, as in 1h30m, 1h 30m or 1 s. The reconnection_interval and heartbeat_interval spellings must be non-zero and no shorter than one microsecond, because the Rust SDK types them as non-zero durations whose wire format carries whole microseconds; reestablish_after takes the zero spellings, which Rust accepts there. The Go client keeps its own reconnect pacing, so the reconnection spellings are validated for compatibility and then ignored, and a value the other SDKs would reject is still rejected here, so one connection string is either valid everywhere or nowhere. The heartbeat_interval and nodelay spellings are applied, because the Go client carries matching options: heartbeat_interval defaults to the client five-second pacing, and nodelay defaults to true, the Go client default, so only nodelay=false ever turns Nagle back on.
Types ¶
type IggyClient ¶
func (*IggyClient) Unwrap ¶ added in v0.10.0
func (c *IggyClient) Unwrap() iggcon.Client
Unwrap is the client of the protocol, which a reader.PartitionReader reads through.
type Option ¶
type Option func(*Options)
func WithLogger ¶ added in v0.9.0
WithLogger sets the logger for the Iggy client and its underlying transport. This logger is used by the heartbeat and forwarded to the transport. When no logger is provided, all internal log output is silently discarded.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
func GetDefaultOptions ¶
func GetDefaultOptions() Options
Directories
¶
| Path | Synopsis |
|---|---|
|
Package reader reads the partitions of a topic with a PartitionReader, which groups them by primary and reads the partitions of a group together, and hands over one message at a time with an IggyConsumer.
|
Package reader reads the partitions of a topic with a PartitionReader, which groups them by primary and reads the partitions of a group together, and hands over one message at a time with an IggyConsumer. |