eventhubs

package
v0.0.0-...-57c00fc Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 14 Imported by: 0

README

Azure Event Hubs

This directory contains samples for managing and using Azure Event Hubs. The following functionality is demonstrated:

You can run the tests in this repo by creating a .env file as described in the root README, and invoking go test -v . from this directory.

Documentation

Overview

Example (EventHubs)
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
// defer goes in LIFO order
defer cancel()
defer resources.Cleanup(context.Background()) // cleanup can take a long time

// create group
var err error
var groupName = config.GenerateGroupName("EventHubs")
config.SetGroupName(groupName)

_, err = resources.CreateGroup(ctx, config.GroupName())
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("created group")

// create Event Hubs namespace
_, err = CreateNamespace(ctx, nsName)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("created namespace")

// create Event Hubs hub
_, err = CreateHub(ctx, nsName, hubName)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("created hub")

// send and receive messages
log.Printf("Send(ctx)\n")
Send(ctx, nsName, hubName)
log.Printf("Receive(ctx)\n")
Receive(ctx, nsName, hubName)
log.Printf("ReceiveViaEPH(ctx)\n")
ReceiveViaEPH(ctx, nsName, hubName, storageAccountName, storageContainerName)
Output:

created group
created namespace
created hub
received: test-message
received: test-message

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHub

func CreateHub(ctx context.Context, nsName string, hubName string) (eventhub.Model, error)

CreateHub creates an Event Hubs hub in a namespace

func CreateNamespace

func CreateNamespace(ctx context.Context, nsName string) (*eventhub.EHNamespace, error)

CreateNamespace creates an Event Hubs namespace

func Receive

func Receive(ctx context.Context, nsName, hubName string)

func ReceiveViaEPH

func ReceiveViaEPH(ctx context.Context, nsName, hubName, storageAccountName, storageContainerName string)

ReceiveViaEPH sets up an Event Processor Host (EPH), a small framework to receive events from several partitions.

func Send

func Send(ctx context.Context, nsName, hubName string)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL