(mq) Fix bug in notice handling where they were registered on the wrong name

This commit is contained in:
Viktor Lofgren 2023-08-05 14:44:16 +02:00
parent bf37a3eb25
commit 715d61dfea

View File

@ -18,29 +18,40 @@ public class ServiceMqSubscription implements MqSubscription {
private final Map<String, Method> notifications = new HashMap<>(); private final Map<String, Method> notifications = new HashMap<>();
private final Service service; private final Service service;
public ServiceMqSubscription(Service service) { public ServiceMqSubscription(Service service) {
this.service = service; this.service = service;
/* Wire up all methods annotated with @MqRequest and @MqNotification
* to receive corresponding messages from this subscription */
for (var method : service.getClass().getMethods()) { for (var method : service.getClass().getMethods()) {
var annotation = method.getAnnotation(MqRequest.class); var annotation = method.getAnnotation(MqRequest.class);
if (annotation != null) { if (annotation != null) {
requests.put(annotation.endpoint(), method); requests.put(annotation.endpoint(), method);
} }
if (method.getAnnotation(MqNotification.class) != null) { }
notifications.put(method.getName(), method);
for (var method : service.getClass().getMethods()) {
var annotation = method.getAnnotation(MqNotification.class);
if (annotation != null) {
notifications.put(annotation.endpoint(), method);
} }
} }
} }
@Override @Override
public boolean filter(MqMessage rawMessage) { public boolean filter(MqMessage rawMessage) {
boolean isInteresting = requests.containsKey(rawMessage.function()) if (requests.containsKey(rawMessage.function())) {
|| notifications.containsKey(rawMessage.function()); return true;
}
if (!isInteresting) { if (notifications.containsKey(rawMessage.function())) {
logger.warn("Received message for unknown function " + rawMessage.function()); return true;
} }
return isInteresting; logger.warn("Received message for unknown function " + rawMessage.function());
return false;
} }
@Override @Override