"e2mgr/logger"
)
-func (*Context) Init(port string, maxMsgSize int, flags int, logger *logger.Logger) *RmrMessenger {//TODO remove pointer from interface
+func (*Context) Init(port string, maxMsgSize int, flags int, logger *logger.Logger) RmrMessenger {
pp := C.CString(port)
defer C.free(unsafe.Pointer(pp))
logger.Debugf("#rmrCgoApi.Init - Going to initiate RMR router")
}
}
logger.Infof("#rmrCgoApi.Init - RMR router has been initiated")
+
+ // Configure the rmr to make rounds of attempts to send a message before notifying the application that it should retry.
+ // Each round is about 1000 attempts with a short sleep between each round.
+ C.rmr_set_stimeout(ctx.RmrCtx, C.int(1000))
r := RmrMessenger(ctx)
- return &r
+ return r
}
-func (ctx *Context) SendMsg(msg *MBuf, maxMsgSize int) (*MBuf, error) {
+func (ctx *Context) SendMsg(msg *MBuf) (*MBuf, error) {
ctx.checkContextInitialized()
ctx.Logger.Debugf("#rmrCgoApi.SendMsg - Going to send message. MBuf: %v", *msg)
- allocatedCMBuf := ctx.getAllocatedCRmrMBuf(ctx.Logger, msg, maxMsgSize)
+ allocatedCMBuf := ctx.getAllocatedCRmrMBuf(ctx.Logger, msg, ctx.MaxMsgSize)
defer C.rmr_free_msg(allocatedCMBuf)
state := allocatedCMBuf.state
if state != RMR_OK {
errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to get allocated message. state: %v - %s", state, states[int(state)])
- ctx.Logger.Errorf(errorMessage)
return nil, errors.New(errorMessage)
}
if state != RMR_OK {
errorMessage := fmt.Sprintf("#rmrCgoApi.SendMsg - Failed to send message. state: %v - %s", state, states[int(state)])
- ctx.Logger.Errorf(errorMessage)
return nil, errors.New(errorMessage)
}
return mbuf, nil
}
-func (ctx *Context) RtsMsg(msg *MBuf) {
- ctx.checkContextInitialized()
- ctx.Logger.Debugf("#rmrCgoApi.RtsMsg - Going to return message to the sender")
- allocatedCMBuf := C.rmr_alloc_msg(ctx.RmrCtx, C.int(ctx.MaxMsgSize))
- defer C.rmr_free_msg(allocatedCMBuf)
- C.rmr_rts_msg(ctx.RmrCtx, allocatedCMBuf)
-}
-
func (ctx *Context) IsReady() bool {
ctx.Logger.Debugf("#rmrCgoApi.IsReady - Going to check if routing table is initialized")
return int(C.rmr_ready(ctx.RmrCtx)) != 0