Documentation ¶
Index ¶
- type AdapterConnector
- func (ac *AdapterConnector) Connect(host string, options *core.Options) error
- func (ac *AdapterConnector) Disconnect() error
- func (ac *AdapterConnector) GetJetStream() nats.JetStreamContext
- func (ac *AdapterConnector) Publish(eventName string, payload []byte, meta map[string]string) (*nats.PubAck, error)
- func (ac *AdapterConnector) PublishAsync(eventName string, payload []byte, meta map[string]string) (nats.PubAckFuture, error)
- func (ac *AdapterConnector) PublishAsyncComplete() <-chan struct{}
- type Compression
- type Error
- type ErrorReply
- type Message
- type Options
- type PubAckFuture
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdapterConnector ¶
type AdapterConnector struct {
// contains filtered or unexported fields
}
func NewAdapterConnector ¶
func NewAdapterConnector(options *Options) *AdapterConnector
NewAdapterConnector creates a new instance of AdapterConnector using the provided options. This function initializes the AdapterConnector with the necessary configurations defined in Options. options: Configuration options for creating the AdapterConnector instance. Returns a pointer to the newly created AdapterConnector.
func NewAdapterConnectorWithClient ¶
func NewAdapterConnectorWithClient(client *core.Client, options *Options) *AdapterConnector
NewAdapterConnectorWithClient creates a new instance of AdapterConnector with an existing core.Client and provided options. This function allows for more control and customization by utilizing an existing client instance. client: An existing core.Client instance to be used by the AdapterConnector. options: Configuration options for creating the AdapterConnector instance. Returns a pointer to the newly created AdapterConnector.
func (*AdapterConnector) Connect ¶
func (ac *AdapterConnector) Connect(host string, options *core.Options) error
Connect establishes a connection to the specified Gravity host using the provided options. host: The address of the Gravity service. options: Configuration options for the connection. Returns an error if the connection attempt fails.
func (*AdapterConnector) Disconnect ¶
func (ac *AdapterConnector) Disconnect() error
Disconnect closes the connection established by the AdapterConnector with the Gravity service. This function is used to cleanly terminate the connection before shutting down the application or when the connection is no longer needed. Returns an error if the disconnection process encounters any issues.
func (*AdapterConnector) GetJetStream ¶ added in v2.0.9
func (ac *AdapterConnector) GetJetStream() nats.JetStreamContext
func (*AdapterConnector) Publish ¶
func (ac *AdapterConnector) Publish(eventName string, payload []byte, meta map[string]string) (*nats.PubAck, error)
Publish sends a message to the specified event name on Gravity. eventName: The name of the event to which the message will be published. payload: The byte array containing the message payload. meta: A map of metadata key-value pairs to be sent along with the message. Returns a PubAck which acknowledges the publishing of the message, and an error if the publishing fails.
Example ¶
ExampleAdapterConnector_Publish demonstrates how to publish an event to the Gravity service using the AdapterConnector. This example starts by establishing a connection to the Gravity service using the core client. It then creates an AdapterConnector with the client and options. The example proceeds to publish an event with a payload and metadata to a specific event name. Note: Replace '0.0.0.0:32803' with your actual Gravity service address. No output is produced as the result of the publishing operation is not printed.
client := core.NewClient() // Connect to Gravity options := core.NewOptions() err := client.Connect("0.0.0.0:32803", options) if err != nil { panic(err) } // Create adapter connector acOpts := NewOptions() ac := NewAdapterConnectorWithClient(client, acOpts) // Publish event meta := map[string]string{ "example": "example", } _, err = ac.Publish("sdk_adapter_event", []byte("sdk_payload"), meta) if err != nil { panic(err) }
Output:
func (*AdapterConnector) PublishAsync ¶
func (ac *AdapterConnector) PublishAsync(eventName string, payload []byte, meta map[string]string) (nats.PubAckFuture, error)
PublishAsync sends a message asynchronously to the specified event name on Gravity. eventName: The name of the event to which the message will be published. payload: The byte array containing the message payload. meta: A map of metadata key-value pairs to be sent along with the message. Returns a PubAckFuture which can be used to receive the acknowledgment of the message once it's published, and an error if the publishing fails.
func (*AdapterConnector) PublishAsyncComplete ¶
func (ac *AdapterConnector) PublishAsyncComplete() <-chan struct{}
PublishAsyncComplete returns a channel that will be closed when all asynchronous publish operations are completed. This can be used to ensure all messages have been published before proceeding.
type Compression ¶ added in v2.0.11
type Compression int32
const ( NoCompression Compression = iota S2Compression )
type ErrorReply ¶
type ErrorReply struct {
Error *Error `json:"error,omitempty"`
}