22
33import com .iexec .common .notification .TaskNotification ;
44import com .iexec .common .notification .TaskNotificationType ;
5- import com .iexec .worker .chain .CredentialsService ;
6- import com .iexec .worker .chain .RevealService ;
75import com .iexec .worker .config .CoreConfigurationService ;
8- import com .iexec .worker .config .PublicConfigurationService ;
96import com .iexec .worker .config .WorkerConfigurationService ;
107import com .iexec .worker .executor .TaskExecutorService ;
11- import com .iexec .worker .feign .CustomFeignClient ;
12- import com .iexec .worker .feign .ResultRepoClient ;
13- import com .iexec .worker .result .ResultService ;
148import lombok .extern .slf4j .Slf4j ;
15-
169import org .springframework .lang .Nullable ;
1710import org .springframework .messaging .converter .MappingJackson2MessageConverter ;
1811import org .springframework .messaging .simp .SimpMessageType ;
1912import org .springframework .messaging .simp .stomp .*;
2013import org .springframework .scheduling .concurrent .ConcurrentTaskScheduler ;
2114import org .springframework .stereotype .Service ;
15+ import org .springframework .web .client .RestTemplate ;
2216import org .springframework .web .socket .client .WebSocketClient ;
2317import org .springframework .web .socket .client .standard .StandardWebSocketClient ;
2418import org .springframework .web .socket .messaging .WebSocketStompClient ;
19+ import org .springframework .web .socket .sockjs .client .RestTemplateXhrTransport ;
20+ import org .springframework .web .socket .sockjs .client .SockJsClient ;
21+ import org .springframework .web .socket .sockjs .client .Transport ;
22+ import org .springframework .web .socket .sockjs .client .WebSocketTransport ;
2523
2624import javax .annotation .PostConstruct ;
2725import java .lang .reflect .Type ;
2826import java .util .ArrayList ;
27+ import java .util .Arrays ;
2928import java .util .List ;
3029import java .util .Map ;
3130import java .util .concurrent .ConcurrentHashMap ;
@@ -38,7 +37,7 @@ public class SubscriptionService extends StompSessionHandlerAdapter {
3837 private final String coreHost ;
3938 private final int corePort ;
4039 private final String workerWalletAddress ;
41-
40+ private RestTemplate restTemplate ;
4241 // external services
4342 private TaskExecutorService taskExecutorService ;
4443
@@ -50,21 +49,17 @@ public class SubscriptionService extends StompSessionHandlerAdapter {
5049
5150 public SubscriptionService (CoreConfigurationService coreConfigurationService ,
5251 WorkerConfigurationService workerConfigurationService ,
53- ResultRepoClient resultRepoClient ,
54- ResultService resultService ,
55- RevealService revealService ,
56- CustomFeignClient feignClient ,
57- PublicConfigurationService publicConfigurationService ,
58- CredentialsService credentialsService ,
59- TaskExecutorService taskExecutorService ) {
52+ TaskExecutorService taskExecutorService ,
53+ RestTemplate restTemplate ) {
6054 this .taskExecutorService = taskExecutorService ;
6155
6256 this .coreHost = coreConfigurationService .getHost ();
6357 this .corePort = coreConfigurationService .getPort ();
6458 this .workerWalletAddress = workerConfigurationService .getWorkerWalletAddress ();
59+ this .restTemplate = restTemplate ;
6560
6661 chainTaskIdToSubscription = new ConcurrentHashMap <>();
67- url = "ws ://" + coreHost + ":" + corePort + "/connect" ;
62+ url = "http ://" + coreHost + ":" + corePort + "/connect" ;
6863 }
6964
7065 @ PostConstruct
@@ -75,7 +70,11 @@ private void run() {
7570 private void restartStomp () {
7671 log .info ("Starting STOMP" );
7772 WebSocketClient webSocketClient = new StandardWebSocketClient ();
78- this .stompClient = new WebSocketStompClient (webSocketClient );
73+ List <Transport > webSocketTransports = Arrays .asList (new WebSocketTransport (webSocketClient ),
74+ new RestTemplateXhrTransport (restTemplate ));
75+ SockJsClient sockJsClient = new SockJsClient (webSocketTransports );
76+ this .stompClient = new WebSocketStompClient (sockJsClient );//without SockJS: new WebSocketStompClient(webSocketClient);
77+ this .stompClient .setAutoStartup (true );
7978 this .stompClient .setMessageConverter (new MappingJackson2MessageConverter ());
8079 this .stompClient .setTaskScheduler (new ConcurrentTaskScheduler ());
8180 this .stompClient .connect (url , this );
0 commit comments