message

package
v0.0.0-...-7077701 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

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.

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.

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.

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.

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.

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.

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.

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.

Index

Constants

View Source
const (
	TopicNameTenant  = "tenant"
	TopicNameProduct = "product"
	TopicNameDevice  = "device"
	TopicNameRule    = "rule"
	TopicNameTriger  = "triger"
)
View Source
const (
	MessageBackendKafka  = "kafka"
	MessageBackendRabbit = "rabbitmq"
)
View Source
const (
	ActionCreate = "create"
	ActionRemove = "remove"
	ActionUpdate = "update"
	ActionStart  = "start"
	ActionStop   = "stop"
)
View Source
const (
	EventTrigerStart = 0
	EventTrigerStop  = 1
)
View Source
const (
	DefaultMessageBackend = MessageBackendRabbit
)

Variables

View Source
var (
	JSONSerialization = SerializeOption{Format: "json"}
)

Functions

func CloseConsumerCluster

func CloseConsumerCluster()

func Deserialize

func Deserialize(buf []byte, opt SerializeOption, obj interface{}) error

func PostMessage

func PostMessage(msg Message, c *Config) (err error)

func PostMessages

func PostMessages(msgs []Message, c *Config) (err error)

func SendMessage

func SendMessage(msg Message, c *Config) (err error)

func SendMessages

func SendMessages(msgs []Message, c *Config) (err error)

func Serialize

func Serialize(msg Message, opt SerializeOption) ([]byte, error)

func StartConsumerCluster

func StartConsumerCluster(khosts string, productKey string, topics []string) error

Types

type Broker

type Broker struct {
	TopicName string
	EventType uint32 `json:"eventType"`
	Payload   []byte `json:"payload"`
}

Broker

func (*Broker) Deserialize

func (p *Broker) Deserialize(buf []byte, opt SerializeOption) error

func (*Broker) Serialize

func (p *Broker) Serialize(opt SerializeOption) ([]byte, error)

func (*Broker) SetTopic

func (p *Broker) SetTopic(name string)

func (*Broker) Topic

func (p *Broker) Topic() string

type Config

type Config struct {
	Backend  string
	User     string
	Password string
	Hosts    string
}

func NewConfig

func NewConfig(backend string, user string, pwd string, hosts string) *Config

func NewConfigWithViper

func NewConfigWithViper() *Config

type Consumer

type Consumer interface {
	WithClientId(clientId string)
	Subscribe(topic string, queueName string, handler MessageHandlerFunc, ctx interface{}) error
	UnSubscribe(topic string) error
	Start() error
	Close()
	SetMessageFactory(factory MessageFactory)
}

func NewConsumer

func NewConsumer(c *Config) (Consumer, error)

type Device

type Device struct {
	TopicName  string
	ProductKey string `json:"productKey"`
	Id         int64  `json:"id"`
	Name       string `json:"name"`
	SerialNo   string `json:"serialno"`
	Action     string `json:"action"`
	Message    string `json:"message"`
}

Device

func (*Device) Deserialize

func (p *Device) Deserialize(buf []byte, opt SerializeOption) error

func (*Device) Serialize

func (p *Device) Serialize(opt SerializeOption) ([]byte, error)

func (*Device) SetTopic

func (p *Device) SetTopic(name string)

func (*Device) Topic

func (p *Device) Topic() string

type Message

type Message interface {
	Topic() string
	SetTopic(name string)
	Serialize(opt SerializeOption) ([]byte, error)
	Deserialize(buf []byte, opt SerializeOption) error
}

type MessageFactory

type MessageFactory interface {
	CreateMessage(topic string) Message
}

type MessageHandlerFunc

type MessageHandlerFunc func(msg Message, ctx interface{})

type Producer

type Producer interface {
	WithClientId(clientId string)
	SendMessage(msg Message) error
	SendMessages(msgs []Message) error
	Close()
}

func NewProducer

func NewProducer(c *Config, sync bool) (Producer, error)

type Product

type Product struct {
	TopicName string
	ProductId string `json:"productId"`
	Action    string `json:"action"`
	TenantId  string `json:"tenantId"`
	Replicas  int32  `json:"replicas"`
}

Product

func (*Product) Deserialize

func (p *Product) Deserialize(buf []byte, opt SerializeOption) error

func (*Product) Serialize

func (p *Product) Serialize(opt SerializeOption) ([]byte, error)

func (*Product) SetTopic

func (p *Product) SetTopic(name string)

func (*Product) Topic

func (p *Product) Topic() string

type Rule

type Rule struct {
	TopicName  string
	RuleName   string            `json:"rule_name"`
	ProductId  string            `json:"product_id"`
	Action     string            `json:"action"`
	Attributes map[string]string `json:"attributes"`
}

Rule

func (*Rule) Deserialize

func (p *Rule) Deserialize(buf []byte, opt SerializeOption) error

func (*Rule) Serialize

func (p *Rule) Serialize(opt SerializeOption) ([]byte, error)

func (*Rule) SetTopic

func (p *Rule) SetTopic(name string)

func (*Rule) Topic

func (p *Rule) Topic() string

type SerializeOption

type SerializeOption struct {
	Format string
}

type Tenant

type Tenant struct {
	TopicName string
	TenantId  string `json:"productId"`
	Action    string `json:"action"`
}

Tenantopic

func (*Tenant) Deserialize

func (p *Tenant) Deserialize(buf []byte, opt SerializeOption) error

func (*Tenant) Serialize

func (p *Tenant) Serialize(opt SerializeOption) ([]byte, error)

func (*Tenant) SetTopic

func (p *Tenant) SetTopic(name string)

func (*Tenant) Topic

func (p *Tenant) Topic() string

Jump to

Keyboard shortcuts

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