mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-17 06:09:53 +05:00
Diameter event publishing, fixes #263
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/history"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -76,7 +77,7 @@ var (
|
||||
debitPeriod = 10 * time.Second
|
||||
globalRoundingDecimals = 5
|
||||
historyScribe history.Scribe
|
||||
pubSubServer PublisherSubscriber
|
||||
pubSubServer rpcclient.RpcClientConnection
|
||||
userService UserService
|
||||
aliasService AliasService
|
||||
)
|
||||
@@ -114,7 +115,7 @@ func SetHistoryScribe(scribe history.Scribe) {
|
||||
historyScribe = scribe
|
||||
}
|
||||
|
||||
func SetPubSub(ps PublisherSubscriber) {
|
||||
func SetPubSub(ps rpcclient.RpcClientConnection) {
|
||||
pubSubServer = ps
|
||||
}
|
||||
|
||||
@@ -129,7 +130,7 @@ func SetAliasService(as AliasService) {
|
||||
func Publish(event CgrEvent) {
|
||||
if pubSubServer != nil {
|
||||
var s string
|
||||
pubSubServer.Publish(event, &s)
|
||||
pubSubServer.Call("PubSubV1.Publish", event, &s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
"github.com/jinzhu/gorm"
|
||||
mgov2 "gopkg.in/mgo.v2"
|
||||
)
|
||||
@@ -66,7 +67,7 @@ func fsCdrHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func NewCdrServer(cgrCfg *config.CGRConfig, cdrDb CdrStorage, rater Connector, pubsub PublisherSubscriber, users UserService, aliases AliasService, stats StatsInterface) (*CdrServer, error) {
|
||||
func NewCdrServer(cgrCfg *config.CGRConfig, cdrDb CdrStorage, rater Connector, pubsub rpcclient.RpcClientConnection, users UserService, aliases AliasService, stats StatsInterface) (*CdrServer, error) {
|
||||
return &CdrServer{cgrCfg: cgrCfg, cdrDb: cdrDb, rater: rater, pubsub: pubsub, users: users, aliases: aliases, stats: stats, guard: &GuardianLock{locksMap: make(map[string]chan bool)}}, nil
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ type CdrServer struct {
|
||||
cgrCfg *config.CGRConfig
|
||||
cdrDb CdrStorage
|
||||
rater Connector
|
||||
pubsub PublisherSubscriber
|
||||
pubsub rpcclient.RpcClientConnection
|
||||
users UserService
|
||||
aliases AliasService
|
||||
stats StatsInterface
|
||||
|
||||
@@ -165,6 +165,53 @@ func (ps *PubSub) ShowSubscribers(in string, out *map[string]*SubscriberData) er
|
||||
return nil
|
||||
}
|
||||
|
||||
// rpcclient.RpcClientConnection interface
|
||||
func (ps *PubSub) Call(serviceMethod string, args interface{}, reply interface{}) error {
|
||||
switch serviceMethod {
|
||||
case "PubSubV1.Subscribe":
|
||||
argsConverted, canConvert := args.(SubscribeInfo)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongArgsType
|
||||
}
|
||||
replyConverted, canConvert := reply.(*string)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongReplyType
|
||||
}
|
||||
return ps.Subscribe(argsConverted, replyConverted)
|
||||
case "PubSubV1.Unsubscribe":
|
||||
argsConverted, canConvert := args.(SubscribeInfo)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongArgsType
|
||||
}
|
||||
replyConverted, canConvert := reply.(*string)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongReplyType
|
||||
}
|
||||
return ps.Unsubscribe(argsConverted, replyConverted)
|
||||
case "PubSubV1.Publish":
|
||||
argsConverted, canConvert := args.(CgrEvent)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongArgsType
|
||||
}
|
||||
replyConverted, canConvert := reply.(*string)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongReplyType
|
||||
}
|
||||
return ps.Publish(argsConverted, replyConverted)
|
||||
case "PubSubV1.ShowSubscribers":
|
||||
argsConverted, canConvert := args.(string)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongArgsType
|
||||
}
|
||||
replyConverted, canConvert := reply.(*map[string]*SubscriberData)
|
||||
if !canConvert {
|
||||
return rpcclient.ErrWrongReplyType
|
||||
}
|
||||
return ps.ShowSubscribers(argsConverted, replyConverted)
|
||||
}
|
||||
return rpcclient.ErrUnsupporteServiceMethod
|
||||
}
|
||||
|
||||
type ProxyPubSub struct {
|
||||
Client *rpcclient.RpcClient
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user