generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
48 lines (39 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2024 Oracle and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at
* https://oss.oracle.com/licenses/upl.
*/
/*
Package main shows how to listen for events on queues.
*/
package main
import (
"context"
"fmt"
"github.com/oracle/coherence-go-client/v2/coherence"
"time"
)
func main() {
var ctx = context.Background()
// create a new Session to the default gRPC port of 1408 using plain text
session, err := coherence.NewSession(ctx, coherence.WithPlainText())
if err != nil {
panic(err)
}
defer session.Close()
namedQueue, err := coherence.GetNamedQueue[string](ctx, session, "queue-events", coherence.Queue)
if err != nil {
panic(err)
}
// Create a listener to monitor for Released events
listener := coherence.NewQueueLifecycleListener[string]().
OnReleased(func(e coherence.QueueLifecycleEvent[string]) {
fmt.Printf("**EVENT=%s: source=%v\n", e.Type(), e.Source())
})
err = namedQueue.AddLifecycleListener(listener)
if err != nil {
panic(err)
}
namedQueue.Release()
time.Sleep(5 * time.Second)
}