rpc

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 3 Imported by: 0

README

The RPC server uses the request-reply design pattern

Introduction

RPC server implements server rabbitmq

Installation
go get -u github.com/thantai574/rpc
Import
import rpc "github.com/thantai574/rpc"
Example setups a server RPC that implements rabbitmq
package main

import (
	"context"
	"github.com/thantai574/rpc"
	"github.com/thantai574/rpc/example/rabbit/msg"
	"github.com/thantai574/rpc/logger"
	"github.com/thantai574/rpc/rabbitmq"

	"github.com/golang/protobuf/proto"
)


func main() {
	ctx := context.Background()
	opt := rpc.RabbitURI("amqp://admin:admin@localhost:5672/")

	log, _ := logger.NewLogger("test", "production")
	var irpc rpc.Irpc
	irpc = rabbitmq.Instance(ctx, opt, log)

	go func() {
		irpc.EventServer(ctx, rabbitmq.RabbitEventServer{
			WhereExchange:   "test",
			WhereRoutingKey: "test",
			Function: func(context.Context) (o proto.Message, e error) {
				o = &msg.PathogenDTO{
					Id:     "1231212",
					Name:   "1",
					Avatar: "2",
				}
				return
			},
		})
	}()
	select {}
}

Example Client RPC rabbitmq
package main

import (
	"context"
	"fmt"

	"github.com/thantai574/rpc"
	"github.com/thantai574/rpc/example/rabbit/msg"
	"github.com/thantai574/rpc/logger"
	"github.com/thantai574/rpc/rabbitmq"
)

func main() {
	ctx := context.Background()
	opt := rpc.RabbitURI("amqp://admin:admin@localhost:5672/")

	log, _ := logger.NewLogger("test", "production")
	var irpc rpc.Irpc

	irpc = rabbitmq.Instance(ctx, opt, log)

	var res = &msg.PathogenDTO{}

	irpc.Publish(ctx, rabbitmq.RabbitMsg{
		WhereExchange:   "test",
		WhereRoutingKey: "test",
		Msg: &msg.PathogenDTO{
			Id:     "1",
			Name:   "1",
			Avatar: "2",
		},
		ReplyMsg: res, // ReplyMsg 
		Reply:    true, // to wait till has a msg 
		Timeout:  time.Minute,
	})

	fmt.Print(res)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ILogger

type ILogger interface {
	Debugw(mgs string, keysAndValues ...interface{})
	Infow(mgs string, keysAndValues ...interface{})
	Warnw(mgs string, keysAndValues ...interface{})
	Errorw(mgs string, keysAndValues ...interface{})
	Fatalw(mgs string, keysAndValues ...interface{})
	Panicw(mgs string, keysAndValues ...interface{})
}

type Irpc

type Irpc interface {
	EventServer(ctx context.Context, request RequestRPC) (err error)
	Publish(ctx context.Context, request RequestMsgRPC) (err error)
}

type Options

type Options interface {
	URIConnection() string
}

type RabbitURI

type RabbitURI string

func (RabbitURI) URIConnection

func (this RabbitURI) URIConnection() string

type RequestMsgRPC

type RequestMsgRPC interface {
	GetExchange() string
	GetRoutingKey() string
	GetMsg() proto.Message
	GetReplyMsg() proto.Message
	HaveReply() bool
	GetTimeout() time.Duration
}

type RequestRPC

type RequestRPC interface {
	GetExchange() string
	GetRoutingKey() string
	GetRpcServer() func(ctx context.Context) (msg proto.Message, err error)
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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