Skip to content

Commit

Permalink
Minor nats correction
Browse files Browse the repository at this point in the history
Added hazelcast
  • Loading branch information
eitam-ring committed Dec 8, 2020
1 parent 903869a commit 70121cb
Show file tree
Hide file tree
Showing 17 changed files with 851 additions and 33 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ A list of supported targets is below.
| Cache | | | | |
| | [Redis](https://redis.io/) |cache.redis | [Usage](targets/cache/redis) | [Example](examples/cache/redis) |
| | [Memcached](https://memcached.org/) |cache.memcached | [Usage](targets/cache/memcached) | [Example](examples/cache/memcached) |
| | [Hazelcast](https://hazelcast.com/) |cache.hazelcast | [Usage](targets/cache/hazelcast) | [Example](examples/cache/hazelcast) |
| Stores/db | | | | |
| | [Postgres](https://www.postgresql.org/) |stores.postgres | [Usage](targets/stores/postgres) | [Example](examples/stores/postgres) |
| | [Mysql](https://www.mysql.com/) |stores.mysql | [Usage](targets/stores/mysql) | [Example](examples/stores/mysql) |
Expand Down
34 changes: 11 additions & 23 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
apiPort: 8081
bindings:
- name: kubemq-query-elastic-search
source:
kind: kubemq.query
name: kubemq-query
properties:
address: "kubemq-cluster:50000"
client_id: "kubemq-query-elastic-search-connector"
auth_token: ""
channel: "query.elastic"
group: ""
auto_reconnect: "true"
reconnect_interval_seconds: "1"
max_reconnects: "0"
target:
kind: stores.elasticsearch
name: target-elasticsearch
properties:
urls: "http://localhost:9201"
username: ""
password: ""
sniff: "false"
- name: hazelcast
source:
kind: kubemq.query
properties:
log_level: "error"
address: localhost:50000
channel: query.hazelcast
target:
kind: cache.hazelcast
properties:
address: localhost:5701
server name: test
properties: {}
13 changes: 13 additions & 0 deletions examples/cache/hazelcast/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
bindings:
- name: hazelcast
source:
kind: kubemq.query
properties:
address: localhost:50000
channel: query.hazelcast
target:
kind: cache.hazelcast
properties:
address: localhost:5701
server_name: test
properties: {}
76 changes: 76 additions & 0 deletions examples/cache/hazelcast/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"fmt"
"github.com/kubemq-hub/kubemq-targets/types"
"github.com/kubemq-io/kubemq-go"
"github.com/nats-io/nuid"
"log"
"time"
)

func main() {
client, err := kubemq.NewClient(context.Background(),
kubemq.WithAddress("localhost", 50000),
kubemq.WithClientId(nuid.Next()),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))
if err != nil {
log.Fatal(err)
}
randomKey := nuid.Next()
// set request
setRequest := types.NewRequest().
SetMetadataKeyValue("method", "set").
SetMetadataKeyValue("map_name", "my_map").
SetMetadataKeyValue("key", randomKey).
SetData([]byte("some-data"))
querySetResponse, err := client.SetQuery(setRequest.ToQuery()).
SetChannel("query.hazelcast").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
setResponse, err := types.ParseResponse(querySetResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("set request for key: %s executed, response: %s", randomKey, setResponse.Metadata.String()))

// get request
getRequest := types.NewRequest().
SetMetadataKeyValue("method", "get").
SetMetadataKeyValue("map_name", "my_map").
SetMetadataKeyValue("key", randomKey)

queryGetResponse, err := client.SetQuery(getRequest.ToQuery()).
SetChannel("query.hazelcast").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
getResponse, err := types.ParseResponse(queryGetResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("get request for key: %s executed, response: %s, data: %s", randomKey, getResponse.Metadata.String(), string(getResponse.Data)))

// delete request

delRequest := types.NewRequest().
SetMetadataKeyValue("method", "delete").
SetMetadataKeyValue("map_name", "my_map").
SetMetadataKeyValue("key", randomKey)

queryDelResponse, err := client.SetQuery(delRequest.ToQuery()).
SetChannel("query.hazelcast").
SetTimeout(10 * time.Second).Send(context.Background())
if err != nil {
log.Fatal(err)
}
delResponse, err := types.ParseResponse(queryDelResponse.Body)
if err != nil {
log.Fatal(err)
}
log.Println(fmt.Sprintf("delete request for key: %s executed, response: %s", randomKey, delResponse.Metadata.String()))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/golang/protobuf v1.4.2
github.com/google/uuid v1.1.2
github.com/googleapis/gax-go/v2 v2.0.5
github.com/hazelcast/hazelcast-go-client v0.6.0
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.10
github.com/kubemq-hub/builder v0.5.9
Expand Down
2 changes: 1 addition & 1 deletion targets-manifest-hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
565eb6ca495589f6e3aff99ce3995a1270b9792147a3dbac9e181493b4e6ceda
c6a0ef67d4d192f0cd37c6755efe732d90cf2213d369a7af4cf87742673bd351
2 changes: 1 addition & 1 deletion targets-manifest.json

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions targets/cache/hazelcast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Kubemq hazelcast Target Connector

Kubemq hazelcast target connector allows services using kubemq server to access hazelcast server functions such `set`, `get` and `delete`.

## Prerequisites
The following are required to run the hazelcast target connector:

- kubemq cluster
- hazelcast
- kubemq-targets deployment

## Configuration

hazelcast target connector configuration properties:

| Properties Key | Required| Description | Example |
|:--------------------------|:--------|:-----------------------------|:-----------------|
| address | yes | hazelcast connection string | "localhost:5701" |
| username | no | hazelcast username | "admin" |
| password | no | hazelcast password | "password" |
| connectionAttemptLimit | no | hazelcast connection attempts(default 1) | 1 |
| connectionAttemptPeriod | no | hazelcast attempt period seconds(default 5) | 5 |
| connectionTimeout | no | hazelcast connection timeout seconds(default 5) | 5 |
| ssl | no | hazelcast use ssl | false |
| sslcertificatefile | no | hazelcast certificate file | "" |
| sslcertificatekey | no | hazelcast certificate key | "" |
| serverName | no | hazelcast server name | "myserver" |

Example:

```yaml
bindings:
- name: kubemq-hazelcast
source:
kind: kubemq.query
properties:
address: localhost:50000
channel: query.hazelcast
target:
kind: cache.hazelcast
properties:
address: localhost:5701
server_name: test
properties: {}

```

## Usage

### Get Request

Get request metadata setting:

| Metadata Key | Required | Description | Possible values |
|:-------------|:---------|:---------------------|:----------------|
| key | yes | hazelcast key string | any string |
| method | yes | get | "get" |
| map_name | yes | hazelcast map name | "my_map" |


Example:

```json
{
"metadata": {
"key": "your-hazelcast-key",
"map_name": "my_map",
"method": "get"
},
"data": null
}
```

### Set Request

Set request metadata setting:

| Metadata Key | Required | Description | Possible values |
|:-------------|:---------|:-----------------|:----------------|
| key | yes | hazelcast key | any string |
| method | yes | set | "set" |
| map_name | yes | hazelcast map name | "my_map" |

Set request data setting:

| Data Key | Required | Description | Possible values |
|:---------|:---------|:----------------------------------|:--------------------|
| data | yes | data to set for the hazelcast key | base64 bytes array |

Example:

```json
{
"metadata": {
"key": "your-hazelcast-key",
"map_name": "my_map",
"method": "set"
},
"data": "c29tZS1kYXRh"
}
```
### Delete Request

Delete request metadata setting:

| Metadata Key | Required | Description | Possible values |
|:-------------|:---------|:---------------------|:----------------|
| key | yes | hazelcast key string | any string |
| method | yes | delete | "delete" |
| map_name | yes | hazelcast map name | "my_map" |


Example:

```json
{
"metadata": {
"key": "your-hazelcast-key",
"map_name": "my_map",
"method": "delete"
},
"data": null
}
```
Loading

0 comments on commit 70121cb

Please sign in to comment.