Commit e6c468ab by 孙龙

up

parent d507859f
# golang-callback_demo
## 如何使用该项目 :
#### 该示例的项目名称为 : go-supplier-sync , 如果你要使用,请自行替换成你的项目名称
### 1.clone项目
git clone ssh://git@119.23.72.7:22611/sunlong_v5/golang-callback_demo.git
### 2.复制项目
1.将golang-callback_demo复制一份成你的自己的项目,比如go-supplier-sync
2.删除.git文件夹,重新初始化git
### 3.修改项目文件夹名称
1.将 golang-callback_demo 改成 go-supplier-sync
2.编辑器批量修改包名 : golang-callback_demo/ => go-supplier-sync/
### 4.修改go.mod文件(重要)
一定要修改go.mod文件,要不然无法跑起来
把go.mod的第一行 : module go-supplier-sync 修改成 module go-supplier-sync
### 5.修改http监听地址
config/proxy.toml.http.addr 修改成你的ip地址或者本地127.0.0.1
### 6.项目启动
go run ./cmd/main.go
go run ./cmd/main.go -config=./config/dev/ -logdir = ./logs/
# golang-callback
功能描述:异步任务转发
gitlab地址:
gitlab:http://119.23.72.7/sunlong_v5/golang-callback
api接口:post
url:http://192.168.1.252:8700/callback
| 参数 | 值类型 | eg | 备注
| ------ | ------ | ------ | ------ |
| callbackDomain | string | crm.liexin.net | 域名domain
| callbackUri | string| api/test5566?a=123&b=456 | uri
| requestType | string | http | 回调请求类型:目前仅支持http/hprose
| callback_func | string | xxoo |hproserpc回调的方法 |
| data | json字符串 | {"user_id":44574} | 回调请求的formdata参数
| method | string | post | http请求类型 支持大小写post/get |
| serviceType | int | 1 | 业务编号,不同业务指定不同的编号,方便与检索 |
| header | json字符串 | {"api-key":"crm a1b2c3d4e5f6g7h8i9jk"} | 回调请求header参数 |
| isHttpJson | int | 0 | http请求是否是json请求方式 1是 0否 |
| remark | string | 测试备注文字 |备注 |
返回:
```
{
"err_code": 0,
"err_msg": "",
"data": []
}
```
注意:所有回调接口的返回参数必须以下面格式为主:
```
{
"err_code": 0,
"err_msg": "",
"data": []
}
```
### .项目启动
http:
go run ./cmd/http/main.go -config=./config/dev/ -logdir = ./logs/
队列监听:
go run ./cmd/task/main.go -config=./config/dev/ -logdir = ./logs/
##项目的目录结构
......
package task
import (
"encoding/json"
"github.com/ichunt2019/cfg/lib"
logger "github.com/ichunt2019/lxLog/log"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
tool "golang-callback/util/lib"
)
type RecvPro struct {
......@@ -12,19 +14,32 @@ type RecvPro struct {
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
//fmt.Println(string(dataByte))
logger.Instance("task").Info(string(dataByte))
//error := PushWechatToYunXin(string(dataByte))
error := Forward(dataByte)
return error
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
defer func() {
if v := recover(); v != nil {
logger.Instance("task").Error("%s",v)
}
}()
logger.Instance("task").Error("任务处理失败了,我要进入db日志库了")
logger.Instance("task").Error("任务处理失败了,发送钉钉消息通知主人")
logger.Instance("task").Error(string(dataByte))
logger.Instance("task").Error("错误原因:%s",err)
//发送钉钉告警
var digndingObj map[string]interface{}
digndingObj = make(map[string]interface{},0)
digndingObj["msgtype"] = "text"
digndingObj["text"] = map[string]string{"content":"异步任务转发告警:我就是我, 5566"}
digndingObj["at"] = map[string]interface{}{"atMobiles":[]string{},"isAtAll":false}
mjson,_ :=json.Marshal(digndingObj)
mString :=string(mjson)
url := lib.Instance("config").GetString("dingding_alert.url")
_,_,_ =tool.HttpJSON(url,mString,10*1000,nil)
return nil
}
......
The file could not be displayed because it is too large.
The file could not be displayed because it is too large.
......@@ -13,6 +13,11 @@ type="direct"
dns="amqp://guest:guest@192.168.1.252:5672/"
[dingding_alert]
url="120.25.127.21:40011/dingding/robot/send/?access_token=9f59ab92d9d416e894ce0e55ce71c17d17641528962fa252bec60b7f8ae003c3"
[owner]
name = "Tom Preston-Werner"
organization = "GitHub"
......
[rabbitmq_golang_async_task]
queue_name="golang_async_task"
routing_key="golang_async_task"
exchange=""
type="direct"
dns="amqp://huntmouser:jy2y2900@172.18.137.23:5672/"
[dingding_alert]
url="120.25.127.21:40011/dingding/robot/send/?access_token=9f59ab92d9d416e894ce0e55ce71c17d17641528962fa252bec60b7f8ae003c3"
[xorm]
ShowSQL = false
[async_task]
data_source_name = "AsYncUxst:AsynCxptwAlz@#@#$ztt@tcp(bigdata.ichunt.db:3306)/liexin_async_task?charset=utf8&parseTime=true&loc=Asia%2FChongqing"
max_open_conn = 20
max_idle_conn = 10
table_prefix = ""
max_conn_life_time = 100
#服务注册名称
micro_service_name = "golang_async_task_http"
#etcd配置信息 etcd服务的ip端口用户密码
[etcd_config]
addrs = [
"192.168.1.252:2379"
]
username = ""
password = ""
#注册到etcd中的ip 端口 权重信息
[etcd_regist]
ip = "172.18.137.41"
port = 60020
weight = 10
[base]
debug_mode="debug"
time_location="Asia/Chongqing"
[http]
addr =":8700" # 监听地址, default ":8700"
read_timeout = 10 # 读取超时时长
write_timeout = 10 # 写入超时时长
max_header_bytes = 20 # 最大的header大小,二进制位长度
[api]
dial_timeout = 20
min_idle_conns = 10
read_timeout = 10
write_timeout = 10
[api.master]
host = "192.168.1.235:6379"
password = "icDb29mLy2s"
[api.slave]
password = "icDb29mLy2s"
host = [
"192.168.1.235:6379",
"192.168.1.237:6379",
]
[sku]
dial_timeout = 20
min_idle_conns = 10
read_timeout = 10
write_timeout = 10
[sku.master]
host = "192.168.1.235:6379"
password = "icDb29mLy2s"
[sku.slave]
password = "icDb29mLy2s"
host = [
"192.168.1.235:6379",
"192.168.1.237:6379",
]
SET CGO_ENABLED=0
SET GOOS=linux
SET GOARCH=amd64
......@@ -57,6 +57,9 @@ func HttpPOST(urlString string, urlParams url.Values, msTimeout int, header http
}
urlParamEncode := urlParams.Encode()
req, err := http.NewRequest("POST", urlString, strings.NewReader(urlParamEncode))
if err != nil{
return nil,nil,err
}
if len(header) > 0 {
req.Header = header
}
......@@ -79,9 +82,14 @@ func HttpJSON(urlString string, jsonContent string, msTimeout int, header http.H
Timeout: time.Duration(msTimeout) * time.Millisecond,
}
req, err := http.NewRequest("POST", urlString, strings.NewReader(jsonContent))
if err != nil{
return nil,nil,err
}
//fmt.Println(err)
if len(header) > 0 {
req.Header = header
}
//fmt.Println(req.Header)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
......
SET CGO_ENABLED=0
SET GOOS=windows
SET GOARCH=amd64
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment