代码拉取完成,页面将自动刷新
package DataCenterClient
import (
"fmt"
RabbitmqRoute "gitee.com/tym_hmm/rabbitmq-pool-router-path-go"
"gitee.com/tym_hmm/route-rabbitmq-client/Conf"
Time "gitee.com/tym_hmm/route-rabbitmq-client/helper"
"strings"
)
const (
//交换机 或 交换机类型 或 队列为空
CODE_CLIENT_EXCHANGE_QUEUE_ERROR = 70100
//转换json失败
CODE_CLIENT_DATA_ENCODE_ERROR = 70101
//媒体类型错误
CODE_CLIENT_TERMINAL_TYPE_ERROR = 70102
)
/**
数据中心客户端
*/
type dataCenterClient struct {
exchangeName string
exchangeType string
queueName string
routeKey string
virtualHosts string
terminalType Conf.TERMINAL_TYPE //客户端类型
baseClient *BaseClient
}
func NewDataCenterClient(host string, port int, usr string, pwd string) DataCenterApi {
return &dataCenterClient{baseClient: &BaseClient{
Host: host,
Port: port,
User: usr,
Pwd: pwd,
}}
}
/**
设置交换机等信息
*/
func (d *dataCenterClient) SetExchange(exchangeName, exChangeType, queueName, routeKey string) {
d.exchangeName = exchangeName
d.exchangeType = exChangeType
d.queueName = queueName
d.routeKey = routeKey
}
func (d *dataCenterClient) SetVirtualHosts(virtualHosts string) {
d.virtualHosts = virtualHosts
}
/**
设置终端
*/
func (d *dataCenterClient) SetTerminalType(terminalType Conf.TERMINAL_TYPE) {
d.terminalType = terminalType
}
/**
数据发送
@param terminalType TERMINAL_TYPE 终端类型
@param routePath string 路由
@param devices DeviceData 设备信息
@param requestData RequestData 数据请求
*/
func (d *dataCenterClient) send(terminalType Conf.TERMINAL_TYPE, routePath string, devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
if !Conf.Check(terminalType) {
return &RabbitmqRoute.RabbitMqTaskError{
Code: CODE_CLIENT_TERMINAL_TYPE_ERROR,
Message: "terminal type error, see Config TERMINAL_TYPE",
}
}
requestData.SdkType = int(terminalType)
requestData.ReportTime = Time.GetNowTimeStr()
json, err := NewRequestData(devices, requestData).EncoderJson()
if err != nil {
return &RabbitmqRoute.RabbitMqTaskError{Code: CODE_CLIENT_DATA_ENCODE_ERROR, Message: err.Error()}
}
if len(strings.TrimSpace(d.exchangeName)) == 0 || len(strings.TrimSpace(d.exchangeType)) == 0 || len(strings.TrimSpace(d.queueName)) == 0 {
return &RabbitmqRoute.RabbitMqTaskError{
Code: CODE_CLIENT_EXCHANGE_QUEUE_ERROR,
Message: "exchangeName, exchangeType, queueName can not be empty",
}
}
if len(strings.TrimSpace(d.virtualHosts)) > 0 {
fmt.Printf("%+v \n", d)
d.baseClient.VirtualHosts = d.virtualHosts
return d.baseClient.GetClientVirtualHosts().Publish(d.exchangeName, d.exchangeType, d.queueName, d.routeKey, routePath, json)
} else {
return d.baseClient.GetClient().Publish(d.exchangeName, d.exchangeType, d.queueName, d.routeKey, routePath, json)
}
}
func (d *dataCenterClient) ReportRequest(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/request", devices, requestData)
}
func (d *dataCenterClient) ReportExpose(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/expose", devices, requestData)
}
func (d *dataCenterClient) ReportClick(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/click", devices, requestData)
}
func (d *dataCenterClient) ReportClose(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/close", devices, requestData)
}
func (d *dataCenterClient) ReportReward(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/reward", devices, requestData)
}
func (d *dataCenterClient) ReportError(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/error", devices, requestData)
}
func (d *dataCenterClient) ReportWake(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/awake", devices, requestData)
}
func (d *dataCenterClient) ReportWakeError(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
return d.send(d.terminalType, "/awake_error", devices, requestData)
}
//func (d *dataCenterClient) ReportThirdRequest(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
// return d.send(d.terminalType,"/third_request", devices, requestData)
//}
//
//func (d *dataCenterClient) ReportThirdComplete(devices *DeviceData, requestData *RequestData) *RabbitmqRoute.RabbitMqTaskError {
// return d.send(d.terminalType,"/third_complete", devices, requestData)
//}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。