We have recently released a new add-on that enables propagating Spring’s application events to all application blocks of the distributed system. You can find it on our marketplace and on GitHub.
With this addon, you can just publish an event via the Events bean, say on the middleware, and all subscribers will receive it no matter where they are running - on the web frontend, on another middleware server (if you have a cluster), etc.
The add-on is not battle-tested yet, so please report about any problems here on the forum or create GitHub issues.
Thank you for trying out the add-on.
Where do you inject the Events bean? Could you show the code?
BTW, the Events bean is a part of the platform, not the add-on.
1. I put it in global module , and Event somehow become null in BeanPropagateEvents.java
---BeanPropagateEvents.java
import com.google.common.base.Strings;
import com.haulmont.cuba.core.global.Events;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
@Component("patrolfoster_eventbean")
public class BeanPropagateEvents {
@Inject
private Events events;
public String sendUiNotificationEvent(String message) {
PropagateEvents propagateEvents =new PropagateEvents(this, Strings.isNullOrEmpty(message) ? "test" : message);
events.publish(propagateEvents);
return "done";
}
}
--------PropagateEvents.java--------
import com.haulmont.addon.globalevents.GlobalApplicationEvent;
import com.haulmont.addon.globalevents.GlobalUiEvent;
public class PropagateEvents extends GlobalApplicationEvent implements
GlobalUiEvent {
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*
*/
private String message;
public PropagateEvents(Object source,String message) {
super(source);
this.message=message;
}
@Override
public Object getSource() {
return super.getSource();
}
public String getMessage() {
return message;
}
}
2. I intend to propagate event from REST to UI
-- REST part for call the bean
new BeanPropagateEvents().sendUiNotificationEvent(userSessionSource.getUserSession().getUser().getLogin());
---UI part for receiver
@EventListener
public void onUiNotificationEvent(PropagateEvents event) {
showMessageDialog("Event
Muncul",event.getMessage(),MessageType.CONFIRMATION);
}
Don’t create beans with the constructor: new BeanPropagateEvents().
You have to inject them or obtain via AppBeans.get(). Then they become managed by the Spring container and injection works.
Could you provide the part of app.log content after publishing the event? It should contain log messages from the com.haulmont.addon.globalevents.* loggers that may help us to track down the issue.
I created UiNotificationEvent in global module by extending GlobalApplicationEvent and implementing GlobalUiEvent.
When the middleware receive entitychangedevent i am sending the UiNotification Event. I dont see the event receiving the UI controller. Is there any additional settings or environment update i need to add for send/receive global events across layers.
First I want to know how do you deploy your projects? in single WAR or double WAR? if in your case the client is deployed in the same JVM as middleware (single WAR) set cuba.useLocalServiceInvocation application property is set to true
otherwise set false
I have two war files(app.war, app-core.war) and i am using tomcat server from cuba studio.
I have cuba.useLocalServiceInvocation set to true.
Kindly let me know if i need to make any changes
hi, @paddu.bits sorry I editing my previous comment because of misleading information, so if you deploying your project in 2 war files, please set cuba.useLocalServiceInvocation to false
I have set cuba.useLocalServiceInvocation to false and tried i still see UI event not receiving controller.
I dont see any logs for websocket in catalina.out.
Do i need to change anything in gradle build file or any properties for events communication between layers