I'm using spring-integration-zeromq and I'm trying to set up with authentication settings.
@Bean
ZeroMqChannel zeroMqPubSubChannel(ZContext context, ObjectMapper objectMapper) {
ZeroMqChannel channel = new ZeroMqChannel(context, true);
channel.setConnectUrl("tcp://localhost:6001:6002");
channel.setConsumeDelay(Duration.ofMillis(100));
channel.setMessageConverter(new GenericMessageConverter());
channel.setSendSocketConfigurer(socket -> {
socket.setZAPDomain("global".getBytes());
socket.setCurveServer(true);
socket.setCurvePublicKey("my_public_key".getBytes());
socket.setCurveSecretKey("my_secret_key".getBytes());
});
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper(objectMapper);
channel.setMessageMapper(mapper);
channel.afterPropertiesSet();
channel.subscribe(m -> System.out.println(m));
return channel;
}
However it seems like results of setSendSocketConfigurer are ignored.
In the org.springframework.integration.zeromq.channel.ZeroMqChannel sendSocketConnectionConfigurer
is inited as an empty lambda and passed as such into prepareSendSocketMono
; so me calling setSendSocketConfigurer
consequently seem to have no effect as it only replaces a property in ZeroMqChannel instance, but not being applied to an already created by then socket mono. How do I set up authentication properly? Am I missing something?
UPD1
After the fix provided by Artem Bilan, the socket configurers seem to have started being applied to the channel, but communication stopped working. I have applied recommendations and tried out setting up ZeroMqProxy in hope it'll provide me with a workaround, but still no success: even my logging subscription in the same config is not coming through the authentication (though it works if I remove the socket configurers calls)
@Configuration
public class ZeroMQConfig {
@Bean
ZeroMqProxy zeroMqProxy(ZContext context, @Value("${zmq.channel.port.frontend}") int frontendPort,
@Value("${zmq.channel.port.backend}") int backendPort) {
ZeroMqProxy proxy = new ZeroMqProxy(context, ZeroMqProxy.Type.SUB_PUB);
proxy.setExposeCaptureSocket(true);
proxy.setFrontendPort(frontendPort);
proxy.setBackendPort(backendPort);
ZCert cert = new ZCert();
proxy.setFrontendSocketConfigurer(socket -> {
socket.setCurvePublicKey(cert.getPublicKey());
socket.setCurveSecretKey(cert.getSecretKey());
socket.setCurveServerKey(Z85.decode("my_server_public_key"));
});
proxy.setBackendSocketConfigurer(socket -> {
socket.setCurvePublicKey(cert.getPublicKey());
socket.setCurveSecretKey(cert.getSecretKey());
socket.setCurveServerKey(Z85.decode("my_server_public_key"));
});
return proxy;
}
@Bean
public ZContext zContext() {
ZContext context = new ZContext();
ZAuth auth = new ZAuth(context);
auth.configureCurve(ZAuth.CURVE_ALLOW_ANY);
auth.setVerbose(true);
return context;
}
@Bean(name = "zeroMqPubChannel")
ZeroMqChannel zeroMqPubChannel(ZContext context, ObjectMapper objectMapper, ZeroMqProxy proxy){
ZeroMqChannel channel = new ZeroMqChannel(context, true);
channel.setZeroMqProxy(proxy);
channel.setConsumeDelay(Duration.ofMillis(100));
channel.setMessageConverter(new GenericMessageConverter());
EmbeddedJsonHeadersMessageMapper mapper = new EmbeddedJsonHeadersMessageMapper(objectMapper);
channel.setMessageMapper(mapper);
return channel;
}
@Bean
@ServiceActivator(inputChannel = "zeroMqPubChannel")
public MessageHandler subscribe() {
return message -> System.out.println(message);
}
}