communication

package module
v0.0.0-...-d4c82a0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: Apache-2.0 Imports: 4 Imported by: 4

README

title

Communication Library


📄 Contents


❕ Description

Common communciation libarary used by all microservices in Epsilon. This libary contains message formats used by the different microservices and the communication handler implementaion for a microservice to communicate with the queue service. All communications in epsilon should be via the queue service.




❕ Using the communication libary


1. The libarary can be imported by adding the link in the import section of the code
import(
  communication "github.com/alexnjh/epsilon/communication"
)
2. Connecting to the queue service (The queue microservice should be running and accessible).

mqUser is the username of the user that the microservice will be using to authenticate with the queue microservice.
mqPass is the password of the user that the microservice will be using to authenticate with the queue microservice.
mqHost is the hostname of the queue microservice.
mqPort is the port that the queue microservice is listening on.
comm, err := communication.NewCommunicationClient(fmt.Sprintf("amqp://%s:%s@%s:%s/",mqUser, mqPass, mqHost, mqPort))
if err != nil {
  log.Fatalf(err.Error())
}
3. Creating a queue

queueName refers the the name of the queue

err = comm.QueueDeclare(queueName)
if err != nil {
  log.Fatalf(err.Error())
}
4. Sending a message to a queue

bytes refers to the message in byte array format to send into the queue
queueName the name of the queue to send the message

err = t.comm.Send(bytes,queueName)

if err != nil{
  return false
}
5. Receiving a message from a queue

msgs refers to a channel that messages will be piped through
receiveQueue the name of the queue to receive messages from

msgs, err := comm.Receive(receiveQueue)
for d := range msgs {
  // Do something to the message 
}


❕ Directory and File Description

Directory Name File name Description
/ interfaces.go Communication interface declaration used between all microservices
/ types.go Contain message types used by the various microservices
/ communications.go Implementation of the communication interface



❕ Common questions



Documentation

Overview

Copyright (C) 2020 Alex Neo

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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Communication

type Communication interface {

	// Send data to a specific queue
	Send(message []byte, queue string) error

	// Receive data from a specific queue
	Receive(queue string) (<-chan amqp.Delivery, error)

	// Connect to a queue microservice
	Connect() error
}

Interface to standadized communication between microservices in the Epsilon distributed system

type CommunicationClient

type CommunicationClient struct {
	// contains filtered or unexported fields
}

CommunicationClient stucture

func NewCommunicationClient

func NewCommunicationClient(host string) (CommunicationClient, error)

Create a new communication client for communication with the queue microservice

func (*CommunicationClient) Connect

func (c *CommunicationClient) Connect() error

Attempt to connect to the queue microservice

func (*CommunicationClient) QueueDeclare

func (c *CommunicationClient) QueueDeclare(queue string) error

Create a new queue to either receive or send messages

func (*CommunicationClient) Receive

func (c *CommunicationClient) Receive(queue string) (<-chan amqp.Delivery, error)

Receive messages from a specific queue

func (*CommunicationClient) Send

func (c *CommunicationClient) Send(message []byte, queue string) error

Send messages to a specific queue

type ExperimentPayload

type ExperimentPayload struct {
	// Type of microservice
	Type string
	// The hostname of the microservice that send this message
	Hostname string
	// The time a microservice receive the pod
	InTime time.Time
	// The the a microservice finish processing a pod
	OutTime time.Time
	// The pod getting processed
	Pod *corev1.Pod
}

Message structure for communicating with the Experiment microservice

type RetryRequest

type RetryRequest struct {
	Req ScheduleRequest
	//Name of the queue the Retry microservice is using
	Queue string
}

Message structure for communicating with the Retry microservice

type ScheduleRequest

type ScheduleRequest struct {
	// A string containing pod details in the following format [pod name]@[namespace]
	Key string
	// Next backoff duration if the pod fails to schedule
	NextBackOffTime int
	// Total time taken to complete scheduling
	ProcessedTime time.Duration
	// Supporting information if required [optional]
	Message string // Supporting information if required [optional]
}

Message structure used by the Scheduler microservice

Jump to

Keyboard shortcuts

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