当前位置:网站首页>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
边栏推荐
- SSM框架系列——Junit单元测试优化day2-3
- 免费试用一个月的服务器,并附上教程
- 进程虚拟地址空间区域划分
- Resolve disagrees about version of symbol device_ create
- 31. Next arrangement
- Baserecyclerviewadapterhelper realizes pull-down refresh and pull-up loading
- Van uploader upload picture implementation process, using native input to upload pictures
- STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
- Introduction to kubernetes
- Remote access to raspberry pie at home (Part 1)
猜你喜欢

mysql中 innoDB执行过程分析

Idea的src子文件下无法创建servlet

CGC: contractual graph clustering for community detection and tracking
![[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)](/img/7d/23e2a611bc6a0d0239abdc79e2e8cf.png)
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)

box-sizing

Servlet监听器&过滤器介绍

Synchronously update the newly added and edited data to the list

Zigbee之CC2530最小系统及寄存器配置(1)

Record the problems encountered in using v-print

bert-base-chinese下载(智取)
随机推荐
航芯技术分享 | ACM32 MCU安全特性概述
box-sizing
Web17 -- use of El and JSTL
Bert base Chinese Download (SMART)
leetcode-791. Custom string sorting
5 free audio material websites, recommended collection
Pytorch: a pit about the implementation of gradreverselayer
About the 'enum' enumeration type and structure.
Servlet监听器&过滤器介绍
(1) Openjuterpyrab comparison scheme
mysql中 innoDB执行过程分析
8 websites that should be known for product development to enhance work experience
大家帮我看一下这是啥情况,MySQL5.5的。谢了
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Redis deployment of cloud native kubesphere
Introduction to servlet listener & filter
在线计算过往日期天数,计算活了多少天
将新增和编辑的数据同步更新到列表
The El table horizontal scroll bar is fixed at the bottom of the visual window
Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats