Documentation ¶
Overview ¶
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See License.txt in the project root for license information.
Index ¶
- type Client
- func NewClient(endpoint string, tokenCredential azcore.TokenCredential, ...) (*Client, error)
- func NewClientWithSAS(endpoint string, sasCred *azcore.SASCredential, options *ClientOptions) (*Client, error)
- func NewClientWithSharedKeyCredential(endpoint string, keyCred *azcore.KeyCredential, options *ClientOptions) (*Client, error)
- func (client *Client) PublishCloudEvents(ctx context.Context, events []messaging.CloudEvent, ...) (PublishCloudEventsResponse, error)
- func (client *Client) PublishCustomEventEvents(ctx context.Context, events []any, options *PublishCustomEventEventsOptions) (PublishCustomEventEventsResponse, error)
- func (client *Client) PublishEvents(ctx context.Context, events []Event, options *PublishEventsOptions) (PublishEventsResponse, error)
- type ClientOptions
- type Event
- type PublishCloudEventsOptions
- type PublishCloudEventsResponse
- type PublishCustomEventEventsOptions
- type PublishCustomEventEventsResponse
- type PublishEventsOptions
- type PublishEventsResponse
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client contains the methods for the Client group. Don't use this type directly, use a constructor function instead.
func NewClient ¶
func NewClient(endpoint string, tokenCredential azcore.TokenCredential, options *ClientOptions) (*Client, error)
NewClient creates a Client that authenticates using a TokenCredential.
Example ¶
package main import ( "fmt" "log" "os" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventgrid/publisher" ) func main() { // ex: https://<topic-name>.<region>.eventgrid.azure.net/api/events endpoint := os.Getenv("EVENTGRID_TOPIC_ENDPOINT") if endpoint == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } // DefaultAzureCredential is a simplified credential type that tries to authenticate via several // different authentication mechanisms. For more control (or more credential types) see the documentation // for the azidentity module: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity tokenCred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } client, err := publisher.NewClient(endpoint, tokenCred, nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } _ = client }
Output:
func NewClientWithSAS ¶
func NewClientWithSAS(endpoint string, sasCred *azcore.SASCredential, options *ClientOptions) (*Client, error)
NewClientWithSAS creates a Client using a shared access signature credential.
Example ¶
// ex: https://<topic-name>.<region>.eventgrid.azure.net/api/events endpoint := os.Getenv("EVENTGRID_TOPIC_ENDPOINT") key := os.Getenv("EVENTGRID_TOPIC_KEY") if endpoint == "" || key == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } client, err := publisher.NewClientWithSAS(endpoint, azcore.NewSASCredential(key), &publisher.ClientOptions{ ClientOptions: policy.ClientOptions{ PerCallPolicies: []policy.Policy{ dumpFullPolicy{"EventGridEvent"}, }, }, }) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } _ = client
Output:
func NewClientWithSharedKeyCredential ¶
func NewClientWithSharedKeyCredential(endpoint string, keyCred *azcore.KeyCredential, options *ClientOptions) (*Client, error)
NewClientWithSharedKeyCredential creates a Client using a shared key credential.
func (*Client) PublishCloudEvents ¶
func (client *Client) PublishCloudEvents(ctx context.Context, events []messaging.CloudEvent, options *PublishCloudEventsOptions) (PublishCloudEventsResponse, error)
PublishCloudEvents - Publishes a batch of events to an Azure Event Grid topic. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2018-01-01
- events - An array of events to be published to Event Grid.
- options - ClientPublishCloudEventEventsOptions contains the optional parameters for the Client.PublishCloudEvents method.
Example ¶
PublishCloudEvents publishes events using the CloudEvent schema to a topic. The topic must be configured to use the CloudEvent schema or this will fail.
package main import ( "context" "fmt" "log" "os" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/messaging" "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventgrid/publisher" ) func main() { // ex: https://<topic-name>.<region>.eventgrid.azure.net/api/events endpoint := os.Getenv("EVENTGRID_CE_TOPIC_ENDPOINT") key := os.Getenv("EVENTGRID_CE_TOPIC_KEY") if endpoint == "" || key == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } // Other authentication methods: // - publisher.NewClient(): authenticate using a TokenCredential from azidentity. // - publisher.NewClientWithSAS(): authenticate using a SAS token. client, err := publisher.NewClientWithSharedKeyCredential(endpoint, azcore.NewKeyCredential(key), nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } cloudEvent, err := messaging.NewCloudEvent("source", "eventtype", "data", nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } events := []messaging.CloudEvent{ cloudEvent, } _, err = client.PublishCloudEvents(context.TODO(), events, nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } }
Output:
func (*Client) PublishCustomEventEvents ¶
func (client *Client) PublishCustomEventEvents(ctx context.Context, events []any, options *PublishCustomEventEventsOptions) (PublishCustomEventEventsResponse, error)
PublishCustomEventEvents - Publishes a batch of events to an Azure Event Grid topic. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2018-01-01
- events - An array of events to be published to Event Grid.
- options - PublishCustomEventEventsOptions contains the optional parameters for the Client.PublishCustomEventEvents method.
func (*Client) PublishEvents ¶
func (client *Client) PublishEvents(ctx context.Context, events []Event, options *PublishEventsOptions) (PublishEventsResponse, error)
PublishEvents - Publishes a batch of events to an Azure Event Grid topic. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2018-01-01
- events - An array of events to be published to Event Grid.
- options - PublishEventsOptions contains the optional parameters for the Client.PublishEvents method.
Example ¶
PublishEvents publishes events using the EventGrid schema to a topic. The topic must be configured to use the EventGrid schema or this will fail.
package main import ( "context" "fmt" "log" "os" "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventgrid/publisher" ) func main() { // ex: https://<topic-name>.<region>.eventgrid.azure.net/api/events endpoint := os.Getenv("EVENTGRID_TOPIC_ENDPOINT") key := os.Getenv("EVENTGRID_TOPIC_KEY") if endpoint == "" || key == "" { fmt.Fprintf(os.Stderr, "Skipping example, environment variables missing\n") return } // Other authentication methods: // - publisher.NewClient(): authenticate using a TokenCredential from azidentity. // - publisher.NewClientWithSAS(): authenticate using a SAS token. client, err := publisher.NewClientWithSharedKeyCredential(endpoint, azcore.NewKeyCredential(key), nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } events := []publisher.Event{ { Data: "data for this event", DataVersion: to.Ptr("1.0"), EventType: to.Ptr("event-type"), EventTime: to.Ptr(time.Now()), ID: to.Ptr("unique-id"), Subject: to.Ptr("subject"), }, } _, err = client.PublishEvents(context.TODO(), events, nil) if err != nil { // TODO: Update the following line with your application specific error handling logic log.Fatalf("ERROR: %s", err) } }
Output:
type ClientOptions ¶
type ClientOptions struct {
azcore.ClientOptions
}
ClientOptions contains optional settings for Client
type Event ¶
type Event struct { // REQUIRED; Event data specific to the event type. Data any // REQUIRED; The schema version of the data object. DataVersion *string // REQUIRED; The time (in UTC) the event was generated. EventTime *time.Time // REQUIRED; The type of the event that occurred. EventType *string // REQUIRED; An unique identifier for the event. ID *string // REQUIRED; A resource path relative to the topic path. Subject *string // The resource path of the event source. Topic *string // READ-ONLY; The schema version of the event metadata. MetadataVersion *string }
Event - Properties of an event published to an Event Grid topic using the EventGrid Schema.
func (Event) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface for type Event.
func (*Event) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaller interface for type Event.
type PublishCloudEventsOptions ¶
type PublishCloudEventsOptions struct { // Required only when publishing to partner namespaces with partner topic routing mode ChannelNameHeader. AegChannelName *string }
PublishCloudEventsOptions contains the optional parameters for the Client.PublishCloudEvents method.
type PublishCloudEventsResponse ¶
type PublishCloudEventsResponse struct { }
PublishCloudEventsResponse contains the response from method Client.PublishCloudEvents.
type PublishCustomEventEventsOptions ¶
type PublishCustomEventEventsOptions struct { }
PublishCustomEventEventsOptions contains the optional parameters for the Client.PublishCustomEventEvents method.
type PublishCustomEventEventsResponse ¶
type PublishCustomEventEventsResponse struct { }
PublishCustomEventEventsResponse contains the response from method Client.PublishCustomEventEvents.
type PublishEventsOptions ¶
type PublishEventsOptions struct { }
PublishEventsOptions contains the optional parameters for the Client.PublishEvents method.
type PublishEventsResponse ¶
type PublishEventsResponse struct { }
PublishEventsResponse contains the response from method Client.PublishEvents.