Hello,I finally found the problem ... It seems that I didn't understood very
well how to use WebSocketMessageBroadcaster from wicket-spring-boot. The
proper way to broadcast websocket messages from an ajax call is to use
org.apache.wicket.protocol.ws.api.WebSocketPushBroadcaster with an
additional configuration of the Executor that must broadcast the messages
using a separate threadFor example, if using springframework (with wicket
application as a bean) you must configure the executor:
                java.util.concurrent.Executor executor =
Executors.newSingleThreadExecutor();    
WebSocketSettings.Holder.get(webApplication).setWebSocketPushMessageExecutor(new
Executor() {                                            @Override               
        public void run(Runnable command) {                     
executor.execute(command);                      }               });
To broadcast messages from business code you can use spring events
(published from your business code) To broadcast from ajax handlers inject
this bean and call broadcastToAll(event) directly. 
/** *  * @author Elvis Ciocoiu * */@Componentpublic class
TaskEventWebSocketBroadcaster { private WebSocketPushBroadcaster
broadcaster;            @Autowired private Application application;             
@PostConstruct
public void init() {            WebSocketSettings webSocketSettings =
WebSocketSettings.Holder.get(application);              
IWebSocketConnectionRegistry
webSocketConnectionRegistry = webSocketSettings.getConnectionRegistry();        
broadcaster = new WebSocketPushBroadcaster(webSocketConnectionRegistry);        
}       
@EventListener  public void onTaskEvent(TaskEvent taskEvent) {  
broadcastToAll(taskEvent);      }               public void 
broadcastToAll(TaskEvent
taskEvent) {            broadcaster.broadcastAll(application, new
TaskEventWebSocketPushMessage(taskEvent));      }               /**      *      
 * @author Elvis
Ciocoiu  *       */     public static class TaskEventWebSocketPushMessage 
implements
IWebSocketPushMessage {         private static final long serialVersionUID = 
1L;                        
private TaskEvent taskEvent;                            public
TaskEventWebSocketPushMessage(TaskEvent taskEvent) {                    
this.taskEvent =
taskEvent;              }                               public TaskEvent 
getTaskEvent() {                       return taskEvent;               }       
}}
I think these distinct scenarios (broadcast from ajaxhandler and from
business thread) should be documented a little more in user guide. Sorry to
waste your time.Thank you

--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to