SetHandlerFuncByMap defines mapping of Request types to RequestHandlerFunc. When a request is received by the broker, it looks up the request type in the map and invoke the found RequestHandlerFunc instance to generate an appropriate reply.
(handlerMap map[string]requestHandlerFunc)
| 101 | // request is received by the broker, it looks up the request type in the map |
| 102 | // and invoke the found RequestHandlerFunc instance to generate an appropriate reply. |
| 103 | func (b *MockBroker) SetHandlerFuncByMap(handlerMap map[string]requestHandlerFunc) { |
| 104 | fnMap := maps.Clone(handlerMap) |
| 105 | b.setHandler(func(req *request) (res encoderWithHeader) { |
| 106 | reqTypeName := reflect.TypeOf(req.body).Elem().Name() |
| 107 | return fnMap[reqTypeName](req) |
| 108 | }) |
| 109 | } |
| 110 | |
| 111 | // SetNotifier set a function that will get invoked whenever a request has been |
| 112 | // processed successfully and will provide the number of bytes read and written |