examples

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: UPL-1.0 Imports: 0 Imported by: 0

README

Coherence Go Client Examples

This directory contains various examples on how to use the Coherence Go client.

Clone the Coherence Go Client Repository
git clone github.com/coherence/coherence-go-client
cd coherence-go-client/examples
Install the Coherence Go Client
go get github.com/oracle/coherence-go-client@latest
Start a Coherence Cluster

Before running any of the examples, you must ensure a Coherence cluster is available. For local development, we recommend using the Coherence CE Docker image; it contains everything necessary for the client to operate correctly.

docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:24.03
Index
Basic Operations

These examples shows how to carry out basic operations against a NamedMap or NamedCache.

Using Primitive Types

This examples runs Put(), Get(), Remove() operations against a NamedMap or NamedCache with key in and value string.

Source code: basic/crud/main.go

go run basic/crud/main.go
Using Structs as values

Source code: basic/struct/main.go

go run basic/struct/main.go
Using Structs as keys and values

Source code: basic/struct_keys/main.go

go run basic/struct_keys/main.go
Using Various contains functions

Source code: basic/contains/main.go

go run basic/contains/main.go
Putting entries that expire

This example uses a NamedCache and issues PutWithExpiry to expire a value after a certain time.

Source code: basic/expiry/main.go

go run basic/expiry/main.go
Setting expiry on cache creation

This example uses a NamedCache that has been created using coherence.WithExpiry option, which will expire all cache entries after the specified time without the need to use PutWithExpiry.

Source code: basic/expiry_cache/main.go

go run basic/expiry_cache/main.go
Using near caches

These example shows how to specify a near-cache for either NamedMap or NamedCache which will cache data accessed via Get() operations on the Go client for fast subsequent local access. Near caches can specify time-to-live (TTL) for entries in a cache as well as number of entries or size of entryes. Any updates of data from the back-end will update the data in the near cache or any data removals will invalidate the near cache.

Near cache with 10 second TTL

Source code: basic/near_cache/ttl/main.go

go run basic/near_cache/ttl/main.go
Near cache with high units of 1000

Source code: basic/near_cache/high_units/main.go

go run basic/near_cache/high_units/main.go
Near cache with high units memory of 10KB

Source code: basic/near_cache/memory/main.go

go run basic/near_cache/memory/main.go
Querying data

These examples shows how to query data operations against a NamedMap or NamedCache.

Querying using keys

Source code: querying/keys/main.go

go run querying/keys/main.go
Querying using filters

Source code: querying/filters/main.go

go run querying/filters/main.go
Querying all data

Note: When using open-ended queries, Coherence internally pages data to ensure that you are not returning all data in one large dataset. Care should still be taken to minimize occurrences of these queries on large caches.

Source code: querying/main.go

go run querying/main.go
Aggregating data

This example shows how to carry out various aggregations against a NamedMap or NamedCache.

Source code: aggregators/main.go

go run aggregators/main.go
Running processors

This example shows how to run entry processors against a or NamedMap or NamedCache with a key of int and value of Person struct.

Source code: processors/standard/main.go

go run processors/standard/main.go

This example shows how to run the same entry processors but use the utility functions to ignore the values returned.

Source code: processors/blind/main.go

go run processors/blind/main.go
Listening for map events

These examples show how to listen for events on a NamedMap or NamedCache.

Listening for all cache events

Source code: events/cache/all/main.go

go run events/cache/all/main.go
Listening for cache insert events

Source code: events/cache/insert/main.go

go run events/cache/insert/main.go
Listening for cache update events

Source code: events/cache/update/main.go

go run events/cache/update/main.go
Listening for cache delete events

Source code: events/cache/delete/main.go

go run events/cache/delete/main.go
Listening for ache events using filters

Source code: events/cache/filters/main.go

go run events/cache/filters/main.go
Listening for cache events using keys

Source code: events/cache/key/main.go

go run events/cache/key/main.go
Listening for map lifecycle events
Listening for truncate cache events

Source code: events/lifecycle/truncated/main.go

go run events/lifecycle/truncated/main.go
Listening for destroyed cache lifecycle events

Source code: events/lifecycle/destroyed/main.go

go run events/lifecycle/destroyed/main.go
Listening for released cache lifecycle events

Source code: events/lifecycle/released/main.go

go run events/lifecycle/released/main.go
Listening for all cache lifecycle events

Source code: events/lifecycle/all/main.go

go run events/lifecycle/all/main.go
Listening for Session Lifecycle Events
Listening for all session events

Source code: events/session/all/main.go

go run events/session/all/main.go
Adding indexes

This example shows how to add a remove indexes on a NamedMap or NamedCache to help query or aggregation performance.

Source code: indexes/main.go

go run indexes/main.go
Working with Queues

This example shows how to work with both standard (NamedQueue) and blocking (NamesBlockingQueue).

Note: This feature is currently only available when using Coherence server version CE 24.04 and above.

Standard

Source code: queues/standard/main.go

go run queues/standard/main.go
Blocking

This example show how to use a blocking queue. Where you can try to issue a Poll() and provide a timeout incase there are no entries on the Queue.

To run this example there are three programs:

  1. queues/blocking/publisher/main.go - Publishes a specified number of orders to a queue
  2. queues/blocking/processor/main.go - Polls() on orders-queue, processes the order and places on processed-queue
  3. queues/blocking/subscriber/main.go - Polls() processed-queue and displays processing time

To run this example, do the following in separate command terminals:

  1. Start a subscriber go run queues/blocking/subscriber/main.go
  2. Start one or more processors go run queues/blocking/processor/main.go
  3. Start a publisher and specify the number orders go run queues/blocking/publisher/main.go 10000
Basic REST server

This example starts a listener on port localhost:17268 which provides a basic REST API providing POST, GET, PUT and DELETE operations against a NamedMap.

Source code: rest/main.go

go run rest/main.go

Documentation

Overview

Package examples provides various examples using the coherence-go-client.

Directories

Path Synopsis
Package main shows aggregation examples using a NamedMap with key of int and value of Person struct.
Package main shows aggregation examples using a NamedMap with key of int and value of Person struct.
basic
contains
Package main shows how to use ContainsKey, ContainsValue and ContainsEntry against a NamedCache.
Package main shows how to use ContainsKey, ContainsValue and ContainsEntry against a NamedCache.
crud
Package main shows how to carry out basic operations against a NamedMap with primitive types.
Package main shows how to carry out basic operations against a NamedMap with primitive types.
expiry
Package main shows how to put entries that expire in a NamedCache.
Package main shows how to put entries that expire in a NamedCache.
expiry_cache
Package main shows how to put entries that expire in a NamedCache using the coherence.WithExpiry option.
Package main shows how to put entries that expire in a NamedCache using the coherence.WithExpiry option.
near_cache/high_units
Package main shows how to use a near cache with a NamedMap or NamedCache with high units of 1000.
Package main shows how to use a near cache with a NamedMap or NamedCache with high units of 1000.
near_cache/memory
Package main shows how to use a near cache with a NamedMap or NamedCache with high units memory of 10k.
Package main shows how to use a near cache with a NamedMap or NamedCache with high units memory of 10k.
near_cache/ttl
Package main shows how to use a near cache with a NamedMap or NamedCache with an expiry of 10 seconds.
Package main shows how to use a near cache with a NamedMap or NamedCache with an expiry of 10 seconds.
struct
Package main shows how to carry out basic operations against a NamedMap with a key of int and value of Person struct.
Package main shows how to carry out basic operations against a NamedMap with a key of int and value of Person struct.
struct_keys
Package main shows how to carry out basic operations against a NamedMap where a key and value are structs.
Package main shows how to carry out basic operations against a NamedMap where a key and value are structs.
Package events shows examples using events.
Package events shows examples using events.
cache
Package cache shows examples using MapEvents.
Package cache shows examples using MapEvents.
cache/all
Package main shows how to listen for all events on a NamedMap or NamedCache.
Package main shows how to listen for all events on a NamedMap or NamedCache.
cache/delete
Package main shows how to listen for delete events on a NamedMap or NamedCache.
Package main shows how to listen for delete events on a NamedMap or NamedCache.
cache/filters
Package main shows how to listen for all events on a NamedMap or NamedCache using filters.
Package main shows how to listen for all events on a NamedMap or NamedCache using filters.
cache/insert
Package main shows how to listen for insert events on a NamedMap or NamedCache.
Package main shows how to listen for insert events on a NamedMap or NamedCache.
cache/key
Package main shows how to listen for events on a NamedMap or NamedCache for a specific key.
Package main shows how to listen for events on a NamedMap or NamedCache for a specific key.
cache/people_insert
Package main inserts entries into a people NamedMap insert PutAll().
Package main inserts entries into a people NamedMap insert PutAll().
cache/people_listen
Package main listens for all events on a NamedMap or NamedCache.
Package main listens for all events on a NamedMap or NamedCache.
cache/update
Package main shows how to listen for update events on a NamedMap or NamedCache.
Package main shows how to listen for update events on a NamedMap or NamedCache.
lifecycle/all
Package main shows how to listen for all lifecycle events on a NamedMap or NamedCache.
Package main shows how to listen for all lifecycle events on a NamedMap or NamedCache.
lifecycle/destroyed
Package main shows how to listen for destroyed events on a NamedMap or NamedCache.
Package main shows how to listen for destroyed events on a NamedMap or NamedCache.
lifecycle/released
Package main shows how to listen for released events on a NamedMap or NamedCache.
Package main shows how to listen for released events on a NamedMap or NamedCache.
lifecycle/truncated
Package main shows how to listen for truncated events on a NamedMap or NamedCache.
Package main shows how to listen for truncated events on a NamedMap or NamedCache.
session/all
Package main shows how to listen for all session events on a NamedMap or NamedCache.
Package main shows how to listen for all session events on a NamedMap or NamedCache.
Package main shows examples using indexes.
Package main shows examples using indexes.
processors
blind
Package main shows how to run processors against a NamedMap or NamedCache using the *Blind utilities methods.
Package main shows how to run processors against a NamedMap or NamedCache using the *Blind utilities methods.
standard
Package main shows how to run processors against a NamedMap or NamedCache.
Package main shows how to run processors against a NamedMap or NamedCache.
Package main shows how to run open-ended queries against a NamedMap or NamedCache using keys.
Package main shows how to run open-ended queries against a NamedMap or NamedCache using keys.
filters
Package main shows how to run queries against a NamedMap or NamedCache using filters.
Package main shows how to run queries against a NamedMap or NamedCache using filters.
keys
Package main shows how to run queries against a NamedMap or NamedCache using keys.
Package main shows how to run queries against a NamedMap or NamedCache using keys.
Package main shows examples using queues.
Package main shows examples using queues.
blocking/processor
Package main shows how to use a blocking queue.
Package main shows how to use a blocking queue.
blocking/publisher
Package main shows how to use a blocking queue.
Package main shows how to use a blocking queue.
blocking/subscriber
Package main shows how to use a blocking queue.
Package main shows how to use a blocking queue.
standard
Package main shows how to use queues.
Package main shows how to use queues.
Package main starts a listener on port localhost:17268 which provides a basic REST API providing POST, GET, PUT and DELETE operations against a NamedMap.
Package main starts a listener on port localhost:17268 which provides a basic REST API providing POST, GET, PUT and DELETE operations against a NamedMap.

Jump to

Keyboard shortcuts

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