当前位置:网站首页>Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
2022-04-23 12:56:00 【Play ha ha 527】
go iris Multi service implementation framework Demo: adopt ( monitor 8083 Port of ) service 1 Interface startup in ( monitor 8084 Port of ) service 2
Preface
Usually , Multiple services on different ports will be monitored in an application , such as : service 1 Realize its corresponding interface functions , service 2 Realize its corresponding interface functions . this demo Example , The purpose is : By serving 1 To start the service 2.One 、DEMO Example
1. Import and stock in
The code is as follows ( Example ):
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/kataras/iris/v12"
"golang.org/x/sync/errgroup"
)
var g errgroup.Group
var sig string
var app2 *iris.Application
func main() {
sig = "start"
g.Go(startApp1)
if err := g.Wait(); err != nil {
fmt.Println(fmt.Sprintf("startup service failed, err:%v\n", err))
}
}
func startApp1() error {
app := iris.New()
app.Handle("GET", "/hello1", hello1)
app.Handle("GET", "/restart", restart)
log.Println("http://localhost:8083/hello1")
log.Println("http://localhost:8084/hello2")
log.Println("http://localhost:8083/restart")
err := app.Listen(":8083")
return err
}
func startApp2() error {
var err error
app2 = iris.New()
app2.Handle("GET", "/hello2", hello2)
err = app2.Listen(":8084")
return err
}
func restart(c iris.Context) {
if sig == "start" {
g.Go(startApp2)
fmt.Println(" Started http://localhost:8084")
sig = "restart"
} else if sig == "restart" {
// lsnrctl stop
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
if err := app2.Shutdown(ctx); nil != err {
log.Fatalf("server shutdown failed, err: %v\n", err)
}
log.Println("server gracefully shutdown")
fmt.Println(" Has stopped http://localhost:8084")
// Start listening
g.Go(startApp2)
//app2.Listen(":8084")
fmt.Println(" Started http://localhost:8084")
sig = "restart"
}
c.WriteString(" Restarted ")
}
func hello1(c iris.Context) {
c.WriteString("hello app1")
}
func hello2(c iris.Context) {
c.WriteString("hello app2")
}
summary
Completed function flow :1. Start the program , service 1 Listening port http://localhost:8083, Contains interfaces :http://localhost:8083/hello1 and http://localhost:8083/restart
2. adopt http://localhost:8083/restart Interface start service 2
3. service 2 After starting , Its interface http://localhost:8084/hello2 Normal use
版权声明
本文为[Play ha ha 527]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230615231119.html
边栏推荐
- Huawei cloud MVP email
- Servlet监听器&过滤器介绍
- SSM framework series - data source configuration day2-1
- After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
- 大家帮我看一下这是啥情况,MySQL5.5的。谢了
- 梳理網絡IP代理的幾大用途
- Software testing weekly (issue 68): the best way to solve difficult problems is to wait and see the changes and push the boat with the current.
- 解决disagrees about version of symbol device_create
- 洛谷P5540 [BalkanOI2011] timeismoney | 最小乘积生成树 题解
- 风尚云网学习-h5的input:type属性的image属性
猜你喜欢

使用Source Insight查看编辑源代码

4. DRF permission & access frequency & filtering & sorting

Homomorphic encryption technology learning

NPDP | how can product managers not be excluded by programmers?

数据库中的日期时间类型

Pytorch: a pit about the implementation of gradreverselayer

有趣的IDEA插件推荐,给你的开发工作增添色彩

V-model binding value in El select, data echo only displays value, not label

SSM框架系列——Junit单元测试优化day2-3

Record some NPM related problems (messy records)
随机推荐
精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
梳理网络IP代理的几大用途
【每日一题】棋盘问题
Process virtual address space partition
31. 下一个排列
RT-thread中关键词解释及部分API
[daily question] chessboard question
Record a website for querying compatibility, string Replaceall() compatibility error
实现一个盒子在父盒子中水平垂直居中的几种“姿势”
网站首页文件被攻击篡改的形式有哪些
BUUCTF WEB [BJDCTF2020]The mystery of ip
洛谷P3236 [HNOI2014]画框 题解
Luogu p5540 [balkanoi2011] timeismoney | minimum product spanning tree problem solution
leetcode:437. 路径总和 III【dfs 选还是不选?】
22. 括号生成
Remote sensing image classification and recognition system based on convolutional neural network
Deploying MySQL in cloud native kubesphere
Luogu p3236 [hnoi2014] picture frame solution
AD20补充笔记3—快捷键+持续更新