pulsar

package
Version: v0.4.0-candidat...-a624cdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DlqTopicSuffix    = "-DLQ"
	RetryTopicSuffix  = "-RETRY"
	MaxReconsumeTimes = 16

	SysPropertyDelayTime       = "DELAY_TIME"
	SysPropertyRealTopic       = "REAL_TOPIC"
	SysPropertyRetryTopic      = "RETRY_TOPIC"
	SysPropertyReconsumeTimes  = "RECONSUMETIMES"
	SysPropertyOriginMessageID = "ORIGIN_MESSAGE_IDY_TIME"
)
View Source
const (
	IoMaxSize = 1024
)

Variables

View Source
var ErrConsumerClosed = errors.New("consumer closed")

Functions

func GetBatcherBuilderProvider

func GetBatcherBuilderProvider(typ BatcherBuilderType) (
	internal.BatcherBuilderProvider, error,
)

func NewDefaultRouter

func NewDefaultRouter(
	hashFunc func(string) uint32,
	maxBatchingMessages uint,
	maxBatchingSize uint,
	maxBatchingDelay time.Duration,
	disableBatching bool) func(*ProducerMessage, uint32) int

NewDefaultRouter set the message routing mode for the partitioned producer. Default routing mode is round-robin routing if no partition key is specified. If the batching is enabled, it honors the different thresholds for batching i.e. maximum batch size, maximum number of messages, maximum delay to publish a batch. When one of the threshold is reached the next partition is used.

func ReadElements

func ReadElements(r io.Reader, elements ...interface{}) error

func WriteElements

func WriteElements(w io.Writer, elements ...interface{}) error

Types

type Authentication

type Authentication interface{}

Opaque interface that represents the authentication credentials

func NewAuthentication

func NewAuthentication(name string, params string) (Authentication, error)

func NewAuthenticationAthenz

func NewAuthenticationAthenz(authParams map[string]string) Authentication

func NewAuthenticationFromTLSCertSupplier

func NewAuthenticationFromTLSCertSupplier(tlsCertSupplier func() (*tls.Certificate, error)) Authentication

Create new Authentication provider with specified TLS certificate supplier

func NewAuthenticationOAuth2

func NewAuthenticationOAuth2(authParams map[string]string) Authentication

func NewAuthenticationTLS

func NewAuthenticationTLS(certificatePath string, privateKeyPath string) Authentication

Create new Authentication provider with specified TLS certificate and private key

func NewAuthenticationToken

func NewAuthenticationToken(token string) Authentication

Create new Authentication provider with specified auth token

func NewAuthenticationTokenFromFile

func NewAuthenticationTokenFromFile(tokenFilePath string) Authentication

Create new Authentication provider with specified auth token from a file

func NewAuthenticationTokenFromSupplier

func NewAuthenticationTokenFromSupplier(tokenSupplier func() (string, error)) Authentication

NewAuthenticationTokenFromSupplier returns a token auth provider that gets the token data from a user supplied function. The function is invoked each time the client library needs to use a token in talking with Pulsar brokers

type AvroCodec

type AvroCodec struct {
	Codec *goavro.Codec
}

func NewSchemaDefinition

func NewSchemaDefinition(schema *goavro.Codec) *AvroCodec

type AvroSchema

type AvroSchema struct {
	AvroCodec
	SchemaInfo
}

func NewAvroSchema

func NewAvroSchema(avroSchemaDef string, properties map[string]string) *AvroSchema

func (*AvroSchema) Decode

func (as *AvroSchema) Decode(data []byte, v interface{}) error

func (*AvroSchema) Encode

func (as *AvroSchema) Encode(data interface{}) ([]byte, error)

func (*AvroSchema) GetSchemaInfo

func (as *AvroSchema) GetSchemaInfo() *SchemaInfo

func (*AvroSchema) Validate

func (as *AvroSchema) Validate(message []byte) error

type BatcherBuilderType

type BatcherBuilderType int
const (
	DefaultBatchBuilder BatcherBuilderType = iota
	KeyBasedBatchBuilder
)

type BinaryFreeList

type BinaryFreeList chan []byte
var BinarySerializer BinaryFreeList = make(chan []byte, IoMaxSize)

func (BinaryFreeList) Borrow

func (b BinaryFreeList) Borrow() (buf []byte)

func (BinaryFreeList) Float32

func (b BinaryFreeList) Float32(buf []byte) (float32, error)

func (BinaryFreeList) Float64

func (b BinaryFreeList) Float64(buf []byte) (float64, error)

func (BinaryFreeList) PutDouble

func (b BinaryFreeList) PutDouble(datum interface{}) ([]byte, error)

func (BinaryFreeList) PutFloat

func (b BinaryFreeList) PutFloat(datum interface{}) ([]byte, error)

func (BinaryFreeList) PutUint16

func (b BinaryFreeList) PutUint16(w io.Writer, byteOrder binary.ByteOrder, val uint16) error

func (BinaryFreeList) PutUint32

func (b BinaryFreeList) PutUint32(w io.Writer, byteOrder binary.ByteOrder, val uint32) error

func (BinaryFreeList) PutUint64

func (b BinaryFreeList) PutUint64(w io.Writer, byteOrder binary.ByteOrder, val uint64) error

func (BinaryFreeList) PutUint8

func (b BinaryFreeList) PutUint8(w io.Writer, val uint8) error

func (BinaryFreeList) Return

func (b BinaryFreeList) Return(buf []byte)

func (BinaryFreeList) Uint16

func (b BinaryFreeList) Uint16(r io.Reader, byteOrder binary.ByteOrder) (uint16, error)

func (BinaryFreeList) Uint32

func (b BinaryFreeList) Uint32(r io.Reader, byteOrder binary.ByteOrder) (uint32, error)

func (BinaryFreeList) Uint64

func (b BinaryFreeList) Uint64(r io.Reader, byteOrder binary.ByteOrder) (uint64, error)

func (BinaryFreeList) Uint8

func (b BinaryFreeList) Uint8(r io.Reader) (uint8, error)

type BytesSchema

type BytesSchema struct {
	SchemaInfo
}

func NewBytesSchema

func NewBytesSchema(properties map[string]string) *BytesSchema

func (*BytesSchema) Decode

func (bs *BytesSchema) Decode(data []byte, v interface{}) error

func (*BytesSchema) Encode

func (bs *BytesSchema) Encode(data interface{}) ([]byte, error)

func (*BytesSchema) GetSchemaInfo

func (bs *BytesSchema) GetSchemaInfo() *SchemaInfo

func (*BytesSchema) Validate

func (bs *BytesSchema) Validate(message []byte) error

type Client

type Client interface {
	// Create the producer instance
	// This method will block until the producer is created successfully
	CreateProducer(ProducerOptions) (Producer, error)

	// Create a `Consumer` by subscribing to a topic.
	//
	// If the subscription does not exist, a new subscription will be created and all messages published after the
	// creation will be retained until acknowledged, even if the consumer is not connected
	Subscribe(ConsumerOptions) (Consumer, error)

	// Create a Reader instance.
	// This method will block until the reader is created successfully.
	CreateReader(ReaderOptions) (Reader, error)

	// Fetch the list of partitions for a given topic
	//
	// If the topic is partitioned, this will return a list of partition names.
	// If the topic is not partitioned, the returned list will contain the topic
	// name itself.
	//
	// This can be used to discover the partitions and create {@link Reader},
	// {@link Consumer} or {@link Producer} instances directly on a particular partition.
	TopicPartitions(topic string) ([]string, error)

	// Close the Client and free associated resources
	Close()
}

func NewClient

func NewClient(options ClientOptions) (Client, error)

type ClientOptions

type ClientOptions struct {
	// Configure the service URL for the Pulsar service.
	// This parameter is required
	URL string

	// Timeout for the establishment of a TCP connection (default: 5 seconds)
	ConnectionTimeout time.Duration

	// Set the operation timeout (default: 30 seconds)
	// Producer-create, subscribe and unsubscribe operations will be retried until this interval, after which the
	// operation will be marked as failed
	OperationTimeout time.Duration

	// Configure the authentication provider. (default: no authentication)
	// Example: `Authentication: NewAuthenticationTLS("my-cert.pem", "my-key.pem")`
	Authentication

	// Set the path to the trusted TLS certificate file
	TLSTrustCertsFilePath string

	// Configure whether the Pulsar client accept untrusted TLS certificate from broker (default: false)
	TLSAllowInsecureConnection bool

	// Configure whether the Pulsar client verify the validity of the host name from broker (default: false)
	TLSValidateHostname bool

	// Max number of connections to a single broker that will kept in the pool. (Default: 1 connection)
	MaxConnectionsPerBroker int

	// Configure the logger used by the client.
	// By default, a wrapped logrus.StandardLogger will be used, namely,
	// log.NewLoggerWithLogrus(logrus.StandardLogger())
	// FIXME: use `logger` as internal field name instead of `log` as it's more idiomatic
	Logger log.Logger

	// Add custom labels to all the metrics reported by this client instance
	CustomMetricsLabels map[string]string
}

Builder interface that is used to construct a Pulsar Client instance.

type CompressionLevel

type CompressionLevel int
const (
	// Default compression level
	Default CompressionLevel = iota

	// Faster compression, with lower compression ration
	Faster

	// Higher compression rate, but slower
	Better
)

type CompressionType

type CompressionType int
const (
	NoCompression CompressionType = iota
	LZ4
	ZLib
	ZSTD
)

type Consumer

type Consumer interface {
	// Subscription get a subscription for the consumer
	Subscription() string

	// Unsubscribe the consumer
	Unsubscribe() error

	// Receive a single message.
	// This calls blocks until a message is available.
	Receive(context.Context) (Message, error)

	// Chan returns a channel to consume messages from
	Chan() <-chan ConsumerMessage

	// Ack the consumption of a single message
	Ack(Message)

	// AckID the consumption of a single message, identified by its MessageID
	AckID(MessageID)

	// ReconsumeLater mark a message for redelivery after custom delay
	ReconsumeLater(msg Message, delay time.Duration)

	// Acknowledge the failure to process a single message.
	//
	// When a message is "negatively acked" it will be marked for redelivery after
	// some fixed delay. The delay is configurable when constructing the consumer
	// with ConsumerOptions.NAckRedeliveryDelay .
	//
	// This call is not blocking.
	Nack(Message)

	// Acknowledge the failure to process a single message.
	//
	// When a message is "negatively acked" it will be marked for redelivery after
	// some fixed delay. The delay is configurable when constructing the consumer
	// with ConsumerOptions.NackRedeliveryDelay .
	//
	// This call is not blocking.
	NackID(MessageID)

	// Close the consumer and stop the broker to push more messages
	Close()

	// Reset the subscription associated with this consumer to a specific message id.
	// The message id can either be a specific message or represent the first or last messages in the topic.
	//
	// Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the
	//       seek() on the individual partitions.
	Seek(MessageID) error

	// Reset the subscription associated with this consumer to a specific message publish time.
	//
	// Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on
	// the individual partitions.
	//
	// @param timestamp
	//            the message publish time where to reposition the subscription
	//
	SeekByTime(time time.Time) error

	// Name returns the name of consumer.
	Name() string
}

Consumer is an interface that abstracts behavior of Pulsar's consumer

type ConsumerInterceptor

type ConsumerInterceptor interface {
	// BeforeConsume This is called just before the message is send to Consumer's ConsumerMessage channel.
	BeforeConsume(message ConsumerMessage)

	// OnAcknowledge This is called consumer sends the acknowledgment to the broker.
	OnAcknowledge(consumer Consumer, msgID MessageID)

	// OnNegativeAcksSend This method will be called when a redelivery from a negative acknowledge occurs.
	OnNegativeAcksSend(consumer Consumer, msgIDs []MessageID)
}

type ConsumerInterceptors

type ConsumerInterceptors []ConsumerInterceptor

func (ConsumerInterceptors) BeforeConsume

func (x ConsumerInterceptors) BeforeConsume(message ConsumerMessage)

func (ConsumerInterceptors) OnAcknowledge

func (x ConsumerInterceptors) OnAcknowledge(consumer Consumer, msgID MessageID)

func (ConsumerInterceptors) OnNegativeAcksSend

func (x ConsumerInterceptors) OnNegativeAcksSend(consumer Consumer, msgIDs []MessageID)

type ConsumerMessage

type ConsumerMessage struct {
	Consumer
	Message
}

Pair of a Consumer and Message

type ConsumerOptions

type ConsumerOptions struct {
	// Specify the topic this consumer will subscribe on.
	// Either a topic, a list of topics or a topics pattern are required when subscribing
	Topic string

	// Specify a list of topics this consumer will subscribe on.
	// Either a topic, a list of topics or a topics pattern are required when subscribing
	Topics []string

	// Specify a regular expression to subscribe to multiple topics under the same namespace.
	// Either a topic, a list of topics or a topics pattern are required when subscribing
	TopicsPattern string

	// Specify the interval in which to poll for new partitions or new topics if using a TopicsPattern.
	AutoDiscoveryPeriod time.Duration

	// Specify the subscription name for this consumer
	// This argument is required when subscribing
	SubscriptionName string

	// Attach a set of application defined properties to the consumer
	// This properties will be visible in the topic stats
	Properties map[string]string

	// Select the subscription type to be used when subscribing to the topic.
	// Default is `Exclusive`
	Type SubscriptionType

	// InitialPosition at which the cursor will be set when subscribe
	// Default is `Latest`
	SubscriptionInitialPosition

	// Configuration for Dead Letter Queue consumer policy.
	// eg. route the message to topic X after N failed attempts at processing it
	// By default is nil and there's no DLQ
	DLQ *DLQPolicy

	// Configuration for Key Shared consumer policy.
	KeySharedPolicy *KeySharedPolicy

	// Auto retry send messages to default filled DLQPolicy topics
	// Default is false
	RetryEnable bool

	// Sets a `MessageChannel` for the consumer
	// When a message is received, it will be pushed to the channel for consumption
	MessageChannel chan ConsumerMessage

	// Sets the size of the consumer receive queue.
	// The consumer receive queue controls how many messages can be accumulated by the `Consumer` before the
	// application calls `Consumer.receive()`. Using a higher value could potentially increase the consumer
	// throughput at the expense of bigger memory utilization.
	// Default value is `1000` messages and should be good for most use cases.
	ReceiverQueueSize int

	// The delay after which to redeliver the messages that failed to be
	// processed. Default is 1min. (See `Consumer.Nack()`)
	NackRedeliveryDelay time.Duration

	// Set the consumer name.
	Name string

	// If enabled, the consumer will read messages from the compacted topic rather than reading the full message backlog
	// of the topic. This means that, if the topic has been compacted, the consumer will only see the latest value for
	// each key in the topic, up until the point in the topic message backlog that has been compacted. Beyond that
	// point, the messages will be sent as normal.
	//
	// ReadCompacted can only be enabled subscriptions to persistent topics, which have a single active consumer (i.e.
	//  failure or exclusive subscriptions). Attempting to enable it on subscriptions to a non-persistent topics or on a
	//  shared subscription, will lead to the subscription call throwing a PulsarClientException.
	ReadCompacted bool

	// Mark the subscription as replicated to keep it in sync across clusters
	ReplicateSubscriptionState bool

	// A chain of interceptors, These interceptors will be called at some points defined in ConsumerInterceptor interface.
	Interceptors ConsumerInterceptors

	Schema Schema

	// MaxReconnectToBroker set the maximum retry number of reconnectToBroker. (default: ultimate)
	MaxReconnectToBroker *uint
}

ConsumerOptions is used to configure and create instances of Consumer

type DLQPolicy

type DLQPolicy struct {
	// Maximum number of times that a message will be delivered before being sent to the dead letter queue.
	MaxDeliveries uint32

	// Name of the topic where the failing messages will be sent.
	DeadLetterTopic string

	// Name of the topic where the retry messages will be sent.
	RetryLetterTopic string
}

Configuration for Dead Letter Queue consumer policy

type DoubleSchema

type DoubleSchema struct {
	SchemaInfo
}

func NewDoubleSchema

func NewDoubleSchema(properties map[string]string) *DoubleSchema

func (*DoubleSchema) Decode

func (ds *DoubleSchema) Decode(data []byte, v interface{}) error

func (*DoubleSchema) Encode

func (ds *DoubleSchema) Encode(value interface{}) ([]byte, error)

func (*DoubleSchema) GetSchemaInfo

func (ds *DoubleSchema) GetSchemaInfo() *SchemaInfo

func (*DoubleSchema) Validate

func (ds *DoubleSchema) Validate(message []byte) error

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error implement error interface, composed of two parts: msg and result.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Result

func (e *Error) Result() Result

type FloatSchema

type FloatSchema struct {
	SchemaInfo
}

func NewFloatSchema

func NewFloatSchema(properties map[string]string) *FloatSchema

func (*FloatSchema) Decode

func (fs *FloatSchema) Decode(data []byte, v interface{}) error

func (*FloatSchema) Encode

func (fs *FloatSchema) Encode(value interface{}) ([]byte, error)

func (*FloatSchema) GetSchemaInfo

func (fs *FloatSchema) GetSchemaInfo() *SchemaInfo

func (*FloatSchema) Validate

func (fs *FloatSchema) Validate(message []byte) error

type HashingScheme

type HashingScheme int
const (
	// JavaStringHash and Java String.hashCode() equivalent
	JavaStringHash HashingScheme = iota
	// Murmur3_32Hash use Murmur3 hashing function
	Murmur3_32Hash
)

type Int16Schema

type Int16Schema struct {
	SchemaInfo
}

func NewInt16Schema

func NewInt16Schema(properties map[string]string) *Int16Schema

func (*Int16Schema) Decode

func (is16 *Int16Schema) Decode(data []byte, v interface{}) error

func (*Int16Schema) Encode

func (is16 *Int16Schema) Encode(value interface{}) ([]byte, error)

func (*Int16Schema) GetSchemaInfo

func (is16 *Int16Schema) GetSchemaInfo() *SchemaInfo

func (*Int16Schema) Validate

func (is16 *Int16Schema) Validate(message []byte) error

type Int32Schema

type Int32Schema struct {
	SchemaInfo
}

func NewInt32Schema

func NewInt32Schema(properties map[string]string) *Int32Schema

func (*Int32Schema) Decode

func (is32 *Int32Schema) Decode(data []byte, v interface{}) error

func (*Int32Schema) Encode

func (is32 *Int32Schema) Encode(value interface{}) ([]byte, error)

func (*Int32Schema) GetSchemaInfo

func (is32 *Int32Schema) GetSchemaInfo() *SchemaInfo

func (*Int32Schema) Validate

func (is32 *Int32Schema) Validate(message []byte) error

type Int64Schema

type Int64Schema struct {
	SchemaInfo
}

func NewInt64Schema

func NewInt64Schema(properties map[string]string) *Int64Schema

func (*Int64Schema) Decode

func (is64 *Int64Schema) Decode(data []byte, v interface{}) error

func (*Int64Schema) Encode

func (is64 *Int64Schema) Encode(value interface{}) ([]byte, error)

func (*Int64Schema) GetSchemaInfo

func (is64 *Int64Schema) GetSchemaInfo() *SchemaInfo

func (*Int64Schema) Validate

func (is64 *Int64Schema) Validate(message []byte) error

type Int8Schema

type Int8Schema struct {
	SchemaInfo
}

func NewInt8Schema

func NewInt8Schema(properties map[string]string) *Int8Schema

func (*Int8Schema) Decode

func (is8 *Int8Schema) Decode(data []byte, v interface{}) error

func (*Int8Schema) Encode

func (is8 *Int8Schema) Encode(value interface{}) ([]byte, error)

func (*Int8Schema) GetSchemaInfo

func (is8 *Int8Schema) GetSchemaInfo() *SchemaInfo

func (*Int8Schema) Validate

func (is8 *Int8Schema) Validate(message []byte) error

type JSONSchema

type JSONSchema struct {
	AvroCodec
	SchemaInfo
}

func NewJSONSchema

func NewJSONSchema(jsonAvroSchemaDef string, properties map[string]string) *JSONSchema

func (*JSONSchema) Decode

func (js *JSONSchema) Decode(data []byte, v interface{}) error

func (*JSONSchema) Encode

func (js *JSONSchema) Encode(data interface{}) ([]byte, error)

func (*JSONSchema) GetSchemaInfo

func (js *JSONSchema) GetSchemaInfo() *SchemaInfo

func (*JSONSchema) Validate

func (js *JSONSchema) Validate(message []byte) error

type KeySharedPolicy

type KeySharedPolicy struct {
	//KeySharedPolicyMode
	Mode KeySharedPolicyMode
	//HashRanges value pair list
	HashRanges []int
	// If enabled, it will relax the ordering requirement, allowing the broker to send out-of-order messages in case of
	// failures. This will make it faster for new consumers to join without being stalled by an existing slow consumer.
	AllowOutOfOrderDelivery bool
}

KeySharedPolicy for KeyShared subscription

func NewKeySharedPolicySticky

func NewKeySharedPolicySticky(hashRanges []int) (*KeySharedPolicy, error)

NewKeySharedPolicySticky construct KeySharedPolicy in Sticky mode with hashRanges formed in value pair list: [x1, x2, y1, y2, z1, z2], and must not overlap with each others

type KeySharedPolicyMode

type KeySharedPolicyMode int
const (
	// KeySharedPolicyModeAutoSplit Auto split hash range key shared policy.
	KeySharedPolicyModeAutoSplit KeySharedPolicyMode = iota
	// KeySharedPolicyModeSticky is Sticky attach topic with fixed hash range.
	KeySharedPolicyModeSticky
)

type Message

type Message interface {
	// Topic get the topic from which this message originated from
	Topic() string

	// ProducerName returns the name of the producer that has published the message.
	ProducerName() string

	// Properties are application defined key/value pairs that will be attached to the message.
	// Return the properties attached to the message.
	Properties() map[string]string

	// Payload get the payload of the message
	Payload() []byte

	// ID get the unique message ID associated with this message.
	// The message id can be used to univocally refer to a message without having the keep the entire payload in memory.
	ID() MessageID

	// PublishTime get the publish time of this message. The publish time is the timestamp that a client
	// publish the message.
	PublishTime() time.Time

	// EventTime get the event time associated with this message. It is typically set by the applications via
	// `ProducerMessage.EventTime`.
	// If EventTime is 0, it means there isn't any event time associated with this message.
	EventTime() time.Time

	// Key get the key of the message, if any
	Key() string

	// OrderingKey get the ordering key of the message, if any
	OrderingKey() string

	// Get message redelivery count, redelivery count maintain in pulsar broker. When client nack acknowledge messages,
	// broker will dispatch message again with message redelivery count in CommandMessage defined.
	//
	// Message redelivery increases monotonically in a broker, when topic switch ownership to a another broker
	// redelivery count will be recalculated.
	RedeliveryCount() uint32

	// Check whether the message is replicated from other cluster.
	IsReplicated() bool

	// Get name of cluster, from which the message is replicated.
	GetReplicatedFrom() string

	//Get the de-serialized value of the message, according the configured
	GetSchemaValue(v interface{}) error
}

Message abstraction used in Pulsar

type MessageID

type MessageID interface {
	// Serialize the message id into a sequence of bytes that can be stored somewhere else
	Serialize() []byte
}

MessageID identifier for a particular message

func DeserializeMessageID

func DeserializeMessageID(data []byte) (MessageID, error)

DeserializeMessageID reconstruct a MessageID object from its serialized representation

func EarliestMessageID

func EarliestMessageID() MessageID

EarliestMessageID returns a messageID that points to the earliest message available in a topic

func LatestMessageID

func LatestMessageID() MessageID

LatestMessage returns a messageID that points to the latest message

type Producer

type Producer interface {
	// Topic return the topic to which producer is publishing to
	Topic() string

	// Name return the producer name which could have been assigned by the system or specified by the client
	Name() string

	// Send a message
	// This call will be blocking until is successfully acknowledged by the Pulsar broker.
	// Example:
	// producer.Send(ctx, pulsar.ProducerMessage{ Payload: myPayload })
	Send(context.Context, *ProducerMessage) (MessageID, error)

	// SendAsync a message in asynchronous mode
	// This call is blocked when the `event channel` becomes full (default: 10) or the
	// `maxPendingMessages` becomes full (default: 1000)
	// The callback will report back the message being published and
	// the eventual error in publishing
	SendAsync(context.Context, *ProducerMessage, func(MessageID, *ProducerMessage, error))

	// LastSequenceID get the last sequence id that was published by this producer.
	// This represent either the automatically assigned or custom sequence id (set on the ProducerMessage) that
	// was published and acknowledged by the broker.
	// After recreating a producer with the same producer name, this will return the last message that was
	// published in the previous producer session, or -1 if there no message was ever published.
	// return the last sequence id published by this producer.
	LastSequenceID() int64

	// Flush all the messages buffered in the client and wait until all messages have been successfully
	// persisted.
	Flush() error

	// Close the producer and releases resources allocated
	// No more writes will be accepted from this producer. Waits until all pending write request are persisted. In case
	// of errors, pending writes will not be retried.
	Close()
}

Producer is used to publish messages on a topic

type ProducerInterceptor

type ProducerInterceptor interface {
	// BeforeSend This is called before send the message to the brokers. This method is allowed to modify the
	BeforeSend(producer Producer, message *ProducerMessage)

	// OnSendAcknowledgement This method is called when the message sent to the broker has been acknowledged,
	// or when sending the message fails.
	OnSendAcknowledgement(producer Producer, message *ProducerMessage, msgID MessageID)
}

type ProducerInterceptors

type ProducerInterceptors []ProducerInterceptor

func (ProducerInterceptors) BeforeSend

func (x ProducerInterceptors) BeforeSend(producer Producer, message *ProducerMessage)

func (ProducerInterceptors) OnSendAcknowledgement

func (x ProducerInterceptors) OnSendAcknowledgement(producer Producer, message *ProducerMessage, msgID MessageID)

type ProducerMessage

type ProducerMessage struct {
	// Payload for the message
	Payload []byte

	//Value and payload is mutually exclusive, `Value interface{}` for schema message.
	Value interface{}

	// Key sets the key of the message for routing policy
	Key string

	// OrderingKey sets the ordering key of the message
	OrderingKey string

	// Properties attach application defined properties on the message
	Properties map[string]string

	// EventTime set the event time for a given message
	// By default, messages don't have an event time associated, while the publish
	// time will be be always present.
	// Set the event time to a non-zero timestamp to explicitly declare the time
	// that the event "happened", as opposed to when the message is being published.
	EventTime time.Time

	// ReplicationClusters override the replication clusters for this message.
	ReplicationClusters []string

	// SequenceID set the sequence id to assign to the current message
	SequenceID *int64

	// Request to deliver the message only after the specified relative delay.
	// Note: messages are only delivered with delay when a consumer is consuming
	//     through a `SubscriptionType=Shared` subscription. With other subscription
	//     types, the messages will still be delivered immediately.
	DeliverAfter time.Duration

	// Deliver the message only at or after the specified absolute timestamp.
	// Note: messages are only delivered with delay when a consumer is consuming
	//     through a `SubscriptionType=Shared` subscription. With other subscription
	//     types, the messages will still be delivered immediately.
	DeliverAt time.Time
}

ProducerMessage abstraction used in Pulsar producer

type ProducerOptions

type ProducerOptions struct {
	// Topic specify the topic this producer will be publishing on.
	// This argument is required when constructing the producer.
	Topic string

	// Name specify a name for the producer
	// If not assigned, the system will generate a globally unique name which can be access with
	// Producer.ProducerName().
	// When specifying a name, it is up to the user to ensure that, for a given topic, the producer name is unique
	// across all Pulsar's clusters. Brokers will enforce that only a single producer a given name can be publishing on
	// a topic.
	Name string

	// Properties attach a set of application defined properties to the producer
	// This properties will be visible in the topic stats
	Properties map[string]string

	// SendTimeout set the timeout for a message that not be acknowledged by server since sent.
	// Send and SendAsync returns an error after timeout.
	// Default is 30 seconds, negative such as -1 to disable.
	SendTimeout time.Duration

	// DisableBlockIfQueueFull control whether Send and SendAsync block if producer's message queue is full.
	// Default is false, if set to true then Send and SendAsync return error when queue is full.
	DisableBlockIfQueueFull bool

	// MaxPendingMessages set the max size of the queue holding the messages pending to receive an
	// acknowledgment from the broker.
	MaxPendingMessages int

	// HashingScheme change the `HashingScheme` used to chose the partition on where to publish a particular message.
	// Standard hashing functions available are:
	//
	//  - `JavaStringHash` : Java String.hashCode() equivalent
	//  - `Murmur3_32Hash` : Use Murmur3 hashing function.
	// 		https://en.wikipedia.org/wiki/MurmurHash">https://en.wikipedia.org/wiki/MurmurHash
	//
	// Default is `JavaStringHash`.
	HashingScheme

	// CompressionType set the compression type for the producer.
	// By default, message payloads are not compressed. Supported compression types are:
	//  - LZ4
	//  - ZLIB
	//  - ZSTD
	//
	// Note: ZSTD is supported since Pulsar 2.3. Consumers will need to be at least at that
	// release in order to be able to receive messages compressed with ZSTD.
	CompressionType

	// Define the desired compression level. Options:
	// - Default
	// - Faster
	// - Better
	CompressionLevel

	// MessageRouter set a custom message routing policy by passing an implementation of MessageRouter
	// The router is a function that given a particular message and the topic metadata, returns the
	// partition index where the message should be routed to
	MessageRouter func(*ProducerMessage, TopicMetadata) int

	// DisableBatching control whether automatic batching of messages is enabled for the producer. By default batching
	// is enabled.
	// When batching is enabled, multiple calls to Producer.sendAsync can result in a single batch to be sent to the
	// broker, leading to better throughput, especially when publishing small messages. If compression is enabled,
	// messages will be compressed at the batch level, leading to a much better compression ratio for similar headers or
	// contents.
	// When enabled default batch delay is set to 1 ms and default batch size is 1000 messages
	// Setting `DisableBatching: true` will make the producer to send messages individually
	DisableBatching bool

	// BatchingMaxPublishDelay set the time period within which the messages sent will be batched (default: 10ms)
	// if batch messages are enabled. If set to a non zero value, messages will be queued until this time
	// interval or until
	BatchingMaxPublishDelay time.Duration

	// BatchingMaxMessages set the maximum number of messages permitted in a batch. (default: 1000)
	// If set to a value greater than 1, messages will be queued until this threshold is reached or
	// BatchingMaxSize (see below) has been reached or the batch interval has elapsed.
	BatchingMaxMessages uint

	// BatchingMaxSize sets the maximum number of bytes permitted in a batch. (default 128 KB)
	// If set to a value greater than 1, messages will be queued until this threshold is reached or
	// BatchingMaxMessages (see above) has been reached or the batch interval has elapsed.
	BatchingMaxSize uint

	// A chain of interceptors, These interceptors will be called at some points defined in ProducerInterceptor interface
	Interceptors ProducerInterceptors

	Schema Schema

	// MaxReconnectToBroker set the maximum retry number of reconnectToBroker. (default: ultimate)
	MaxReconnectToBroker *uint

	// BatcherBuilderType sets the batch builder type (default DefaultBatchBuilder)
	// This will be used to create batch container when batching is enabled.
	// Options:
	// - DefaultBatchBuilder
	// - KeyBasedBatchBuilder
	BatcherBuilderType
}

type ProtoSchema

type ProtoSchema struct {
	AvroCodec
	SchemaInfo
}

func NewProtoSchema

func NewProtoSchema(protoAvroSchemaDef string, properties map[string]string) *ProtoSchema

func (*ProtoSchema) Decode

func (ps *ProtoSchema) Decode(data []byte, v interface{}) error

func (*ProtoSchema) Encode

func (ps *ProtoSchema) Encode(data interface{}) ([]byte, error)

func (*ProtoSchema) GetSchemaInfo

func (ps *ProtoSchema) GetSchemaInfo() *SchemaInfo

func (*ProtoSchema) Validate

func (ps *ProtoSchema) Validate(message []byte) error

type Reader

type Reader interface {
	// Topic from which this reader is reading from
	Topic() string

	// Next read the next message in the topic, blocking until a message is available
	Next(context.Context) (Message, error)

	// HasNext check if there is any message available to read from the current position
	HasNext() bool

	// Close the reader and stop the broker to push more messages
	Close()

	// Reset the subscription associated with this reader to a specific message id.
	// The message id can either be a specific message or represent the first or last messages in the topic.
	//
	// Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the
	//       seek() on the individual partitions.
	Seek(MessageID) error

	// Reset the subscription associated with this reader to a specific message publish time.
	//
	// Note: this operation can only be done on non-partitioned topics. For these, one can rather perform the seek() on
	// the individual partitions.
	//
	// @param timestamp
	//            the message publish time where to reposition the subscription
	//
	SeekByTime(time time.Time) error
}

Reader can be used to scan through all the messages currently available in a topic.

type ReaderMessage

type ReaderMessage struct {
	Reader
	Message
}

ReaderMessage package Reader and Message as a struct to use

type ReaderOptions

type ReaderOptions struct {
	// Topic specify the topic this consumer will subscribe on.
	// This argument is required when constructing the reader.
	Topic string

	// Name set the reader name.
	Name string

	// Attach a set of application defined properties to the reader
	// This properties will be visible in the topic stats
	Properties map[string]string

	// StartMessageID initial reader positioning is done by specifying a message id. The options are:
	//  * `pulsar.EarliestMessage` : Start reading from the earliest message available in the topic
	//  * `pulsar.LatestMessage` : Start reading from the end topic, only getting messages published after the
	//                           reader was created
	//  * `MessageID` : Start reading from a particular message id, the reader will position itself on that
	//                  specific position. The first message to be read will be the message next to the specified
	//                  messageID
	StartMessageID MessageID

	// If true, the reader will start at the `StartMessageID`, included.
	// Default is `false` and the reader will start from the "next" message
	StartMessageIDInclusive bool

	// MessageChannel sets a `MessageChannel` for the consumer
	// When a message is received, it will be pushed to the channel for consumption
	MessageChannel chan ReaderMessage

	// ReceiverQueueSize sets the size of the consumer receive queue.
	// The consumer receive queue controls how many messages can be accumulated by the Reader before the
	// application calls Reader.readNext(). Using a higher value could potentially increase the consumer
	// throughput at the expense of bigger memory utilization.
	// Default value is {@code 1000} messages and should be good for most use cases.
	ReceiverQueueSize int

	// SubscriptionRolePrefix set the subscription role prefix. The default prefix is "reader".
	SubscriptionRolePrefix string

	// If enabled, the reader will read messages from the compacted topic rather than reading the full message backlog
	// of the topic. This means that, if the topic has been compacted, the reader will only see the latest value for
	// each key in the topic, up until the point in the topic message backlog that has been compacted. Beyond that
	// point, the messages will be sent as normal.
	//
	// ReadCompacted can only be enabled when reading from a persistent topic. Attempting to enable it on non-persistent
	// topics will lead to the reader create call throwing a PulsarClientException.
	ReadCompacted bool
}

ReaderOptions abstraction Reader options to use.

type Result

type Result int

Result used to represent pulsar processing is an alias of type int.

const (
	// ResultOk means no errors
	ResultOk Result = iota
	// ResultUnknownError means unknown error happened on broker
	ResultUnknownError
	// ResultInvalidConfiguration means invalid configuration
	ResultInvalidConfiguration
	// ResultTimeoutError means operation timed out
	ResultTimeoutError
	// ResultLookupError means broker lookup failed
	ResultLookupError
	// ResultInvalidTopicName means invalid topic name
	ResultInvalidTopicName
	// ResultConnectError means failed to connect to broker
	ResultConnectError

	// ReadError means failed to read from socket
	//ReadError                      Result = 6
	// AuthenticationError means authentication failed on broker
	//AuthenticationError            Result = 7
	//AuthorizationError             Result = 8
	//ErrorGettingAuthenticationData Result = 9  // Client cannot find authorization data
	//BrokerMetadataError            Result = 10 // Broker failed in updating metadata
	//BrokerPersistenceError         Result = 11 // Broker failed to persist entry
	//ChecksumError                  Result = 12 // Corrupt message checksum failure
	// ConsumerBusy means Exclusive consumer is already connected
	ConsumerBusy Result = 13
	//NotConnectedError              Result = 14 // Producer/Consumer is not currently connected to broker
	//AlreadyClosedError             Result = 15 // Producer/Consumer is already closed and not accepting any operation
	//InvalidMessage                 Result = 16 // Error in publishing an already used message
	//ConsumerNotInitialized         Result = 17 // Consumer is not initialized
	//ProducerNotInitialized         Result = 18 // Producer is not initialized
	//TooManyLookupRequestException  Result = 19 // Too Many concurrent LookupRequest
	// InvalidUrl means Client Initialized with Invalid Broker Url (VIP Url passed to Client Constructor)
	//InvalidUrl                            Result = 21
	// ServiceUnitNotReady unloaded between client did lookup and producer/consumer got created
	//ServiceUnitNotReady                   Result = 22
	//OperationNotSupported                 Result = 23
	//ProducerBlockedQuotaExceededError     Result = 24 // Producer is blocked
	//ProducerBlockedQuotaExceededException Result = 25 // Producer is getting exception
	//ProducerQueueIsFull                   Result = 26 // Producer queue is full
	//MessageTooBig                         Result = 27 // Trying to send a messages exceeding the max size
	TopicNotFound        Result = 28 // Topic not found
	SubscriptionNotFound Result = 29 // Subscription not found

)

type RetryMessage

type RetryMessage struct {
	// contains filtered or unexported fields
}

type Schema

type Schema interface {
	Encode(v interface{}) ([]byte, error)
	Decode(data []byte, v interface{}) error
	Validate(message []byte) error
	GetSchemaInfo() *SchemaInfo
}

type SchemaInfo

type SchemaInfo struct {
	Name       string
	Schema     string
	Type       SchemaType
	Properties map[string]string
}

Encapsulates data around the schema definition

type SchemaType

type SchemaType int
const (
	NONE     SchemaType = iota //No schema defined
	STRING                     //Simple String encoding with UTF-8
	JSON                       //JSON object encoding and validation
	PROTOBUF                   //Protobuf message encoding and decoding
	AVRO                       //Serialize and deserialize via Avro
	BOOLEAN                    //
	INT8                       //A 8-byte integer.
	INT16                      //A 16-byte integer.
	INT32                      //A 32-byte integer.
	INT64                      //A 64-byte integer.
	FLOAT                      //A float number.
	DOUBLE                     //A double number

	KeyValue         //A Schema that contains Key Schema and Value Schema.
	BYTES       = -1 //A bytes array.
	AUTO        = -2 //
	AutoConsume = -3 //Auto Consume Type.
	AutoPublish = -4 // Auto Publish Type.
)

type StringSchema

type StringSchema struct {
	SchemaInfo
}

func NewStringSchema

func NewStringSchema(properties map[string]string) *StringSchema

func (*StringSchema) Decode

func (ss *StringSchema) Decode(data []byte, v interface{}) error

func (*StringSchema) Encode

func (ss *StringSchema) Encode(v interface{}) ([]byte, error)

func (*StringSchema) GetSchemaInfo

func (ss *StringSchema) GetSchemaInfo() *SchemaInfo

func (*StringSchema) Validate

func (ss *StringSchema) Validate(message []byte) error

type SubscriptionInitialPosition

type SubscriptionInitialPosition int
const (
	// Latest position which means the start consuming position will be the last message
	SubscriptionPositionLatest SubscriptionInitialPosition = iota

	// Earliest position which means the start consuming position will be the first message
	SubscriptionPositionEarliest
)

type SubscriptionType

type SubscriptionType int

SubscriptionType of subscription supported by Pulsar

const (
	// Exclusive there can be only 1 consumer on the same topic with the same subscription name
	Exclusive SubscriptionType = iota

	// Shared subscription mode, multiple consumer will be able to use the same subscription name
	// and the messages will be dispatched according to
	// a round-robin rotation between the connected consumers
	Shared

	// Failover subscription mode, multiple consumer will be able to use the same subscription name
	// but only 1 consumer will receive the messages.
	// If that consumer disconnects, one of the other connected consumers will start receiving messages.
	Failover

	// KeyShared subscription mode, multiple consumer will be able to use the same
	// subscription and all messages with the same key will be dispatched to only one consumer
	KeyShared
)

type TopicMetadata

type TopicMetadata interface {
	// NumPartitions get the number of partitions for the specific topic
	NumPartitions() uint32
}

TopicMetadata is a interface of topic metadata

Directories

Path Synopsis
Package log defines the logger interfaces used by pulsar client.
Package log defines the logger interfaces used by pulsar client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to