Spring loading Artemis broker built-in behavior

Morning everything

Recently, I have been struggling with spring-boot-artemis-starter. My understanding of spring-boot support was as follows:

  • set spring.artemis.mode=embeddedand, like tomcat, spring-boot, will manage the broker available through tcp (server mode). The following command must be successful:nc -zv localhost 61616
  • set spring.artmis.mode=nativeand spring-boot will only configure the jms template according to the properties spring.artemis.*(client mode).

Client mode works fine with a standalone artemis server on my machine. Unfortunately, I was never able to get to the tcp port in server mode.

I would be grateful if someone confirms my understanding of the built-in mode.

Thanks for the tour help

After some digging, I noticed that the implementation provided out of the box using spring-boot-starter-artemis uses an acceptor org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory. I wonder if this is not the main reason (again, I am by no means an expert). But there seems to be a way to tweak the artemis configuration. So I tried the following configuration with no luck:

@SpringBootApplication
public class MyBroker {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(MyBroker.class, args);
    }

    @Autowired
    private ArtemisProperties artemisProperties;

    @Bean
    public ArtemisConfigurationCustomizer artemisConfigurationCustomizer() {
        return configuration -> {
            try {
               configuration.addAcceptorConfiguration("netty", "tcp://localhost:" + artemisProperties.getPort());
            } catch (Exception e) {
                throw new RuntimeException("Failed to add netty transport acceptor to artemis instance");
            }
        };
    }

}
+4
source share
3 answers

Artemis. Spring Artemis Spring bean, EmbeddedJMS. ArtemisEmbeddedConfigurationFactory, InVMAcceptorFactory. bean Artemis ArtemisConfigurationCustomizer bean,

Spring Boot:

import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptorFactory;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ArtemisConfig implements ArtemisConfigurationCustomizer {
    @Override
    public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
        configuration.addConnectorConfiguration("nettyConnector", new TransportConfiguration(NettyConnectorFactory.class.getName()));
        configuration.addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName()));
    }
}
+2

. , InVM. , , , TCP/IP .

+1

, ( Artemis Support) ArtemisConfigurationCustomizer - , , Customizer Spring Boot App , , .

, Customizer application.properties , , , .

Customizer, , .

, :

  • application.properties ArtemisConfigurationCustomizer

  • broker.xml Spring artemis

  • Artemis "in-vm", netty tcp,

  • pub-sub-domain, , . , true JMSListener .

: fooobar.com/questions/709591/...

When using @JmsListener it uses the DefaultMessageListenerContainer which extends the JmsDestinationAccessor, which by default has pubSubDomain set to false. When this property is false, it is queued. If you want to use themes, you must set this property value to true.

In Application.properties:
spring.jms.pub-sub-domain=true

If anyone is interested in the full example, I uploaded it to my github: https://github.com/CorDharel/SpringBootArtemisServerExample

+1
source

Source: https://habr.com/ru/post/1656354/


All Articles