-
Notifications
You must be signed in to change notification settings - Fork 52
/
types.go
55 lines (49 loc) · 2.61 KB
/
types.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
49
50
51
52
53
54
55
/********************************************************************************
* Copyright 2020 Dell Inc.
* Copyright (c) 2021 Intel Corporation
* Copyright (c) 2023 IOTech Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package redis
import (
"crypto/tls"
"github.com/edgexfoundry/go-mod-messaging/v3/pkg/types"
)
const (
// Special identifier used within Redis to signal that a subscriber(consumer) is only interested in the most recent
// messages after the client has connected. Redis provides other functionality to read all the data from a stream
// even if has been read previously, which is what we want to avoid for functional consistency with the other
// implementations of MessageClient.
LatestStreamMessage = "$"
)
// RedisClientCreator type alias for functions which create RedisClient implementation.
//
// This is mostly used for testing purposes so that we can easily inject mocks.
type RedisClientCreator func(redisServerURL string, password string, tlsConfig *tls.Config) (RedisClient, error)
// RedisClient provides functionality needed to read and send messages to/from Redis' Redis Pub/Sub functionality.
//
// The main reason for this interface is to abstract out the underlying client from Client so that it can be mocked and
// allow for easy unit testing. Since 'go-redis' does not leverage interfaces and has complicated entities it can become
// complex to test the operations without requiring a running Redis server.
type RedisClient interface {
// Subscribe creates the subscription in Redis
Subscribe(topic string) error
// Unsubscribe closes the subscription in Redis and removes it.
Unsubscribe(topic string)
// Send sends a message to the specified topic, aka Publish.
Send(topic string, message types.MessageEnvelope) error
// Receive blocking operation which receives the next message for the specified subscribed topic
// This supports multi-level topic scheme with wild cards
Receive(topic string) (*types.MessageEnvelope, error)
// Close cleans up any entities which need to be deconstructed.
Close() error
}