Skip to content

Instantly share code, notes, and snippets.

@jesty
Last active March 24, 2021 15:21
Show Gist options
  • Save jesty/60f6a5e127556e6e0a0e1e6cfd7579cb to your computer and use it in GitHub Desktop.
Save jesty/60f6a5e127556e6e0a0e1e6cfd7579cb to your computer and use it in GitHub Desktop.
Spring Native configuration for an application using Apache Camel, ActiveMQ (JMS) and Elasticsearch
import javax.jms.Session;
import org.apache.activemq.openwire.OpenWireFormatFactory;
import org.apache.activemq.openwire.v12.MarshallerFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.activemq.transport.TransportFactory;
import org.apache.activemq.transport.nio.NIOSSLTransportFactory;
import org.apache.activemq.transport.nio.NIOTransportFactory;
import org.apache.activemq.transport.tcp.TcpTransportFactory;
import org.apache.camel.Endpoint;
import org.apache.camel.component.activemq.ActiveMQComponent;
import org.apache.camel.component.activemq.ActiveMQEndpoint;
import org.apache.camel.component.activemq.converter.ActiveMQConverterLoader;
import org.apache.camel.component.activemq.converter.ActiveMQMessageConverterLoader;
import org.apache.camel.component.file.GenericFileConverterLoader;
import org.apache.camel.component.sjms.SjmsComponent;
import org.apache.camel.converter.CamelBaseBulkConverterLoader;
import org.apache.camel.converter.jaxp.CamelXmlJaxpBulkConverterLoader;
import org.apache.camel.converter.stream.StreamCacheBulkConverterLoader;
import org.apache.camel.impl.engine.DefaultFactoryFinder;
import org.apache.camel.language.property.ExchangePropertyLanguage;
import org.apache.camel.language.property.springboot.ExchangePropertyLanguageAutoConfiguration;
import org.apache.camel.language.property.springboot.ExchangePropertyLanguageConfiguration;
import org.apache.camel.language.simple.SimpleLanguage;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.rest.springboot.RestConfigurationDefinitionAutoConfiguration;
import org.apache.camel.model.rest.springboot.RestConfigurationDefinitionProperties;
import org.apache.camel.processor.DefaultDeferServiceFactory;
import org.apache.camel.processor.DefaultInternalProcessorFactory;
import org.apache.camel.processor.DefaultProcessorFactory;
import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.TransactedPolicy;
import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
import org.apache.camel.spring.converter.ResourceConverterLoader;
import org.apache.camel.spring.spi.SpringTransactionPolicy;
import org.apache.commons.pool2.impl.DefaultEvictionPolicy;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.Script;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.annotation.JmsListeners;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.nativex.hint.AccessBits;
import org.springframework.nativex.hint.InitializationHint;
import org.springframework.nativex.hint.InitializationTime;
import org.springframework.nativex.hint.NativeHint;
import org.springframework.nativex.hint.ProxyHint;
import org.springframework.nativex.hint.ResourceHint;
import org.springframework.nativex.hint.TypeHint;
import org.springframework.transaction.PlatformTransactionManager;
@SpringBootApplication
@NativeHint(
options = {"--enable-http", "--enable-https", "--enable-all-security-services"},
follow = true,
resources = @ResourceHint(
patterns = {"META-INF/services/org/apache/camel/language/resolver/",
"META-INF/services/org/apache/activemq/transport/discoveryagent/masterslave",
"META-INF/services/org/apache/activemq/transport/discoveryagent/multicast",
"META-INF/services/org/apache/activemq/transport/discoveryagent/simple",
"META-INF/services/org/apache/activemq/transport/discoveryagent/static",
"META-INF/services/org/apache/activemq/transport/failover",
"META-INF/services/org/apache/activemq/transport/fanout",
"META-INF/services/org/apache/activemq/transport/mock",
"META-INF/services/org/apache/activemq/transport/multicast",
"META-INF/services/org/apache/activemq/transport/nio",
"META-INF/services/org/apache/activemq/transport/nio+ssl",
"META-INF/services/org/apache/activemq/transport/ssl",
"META-INF/services/org/apache/activemq/transport/tcp",
"META-INF/services/org/apache/activemq/transport/udp",
"META-INF/services/org/apache/activemq/wireformat/default"
}),
types = {
@TypeHint(types = {JmsListener.class, JmsListeners.class},
access = AccessBits.ALL),
@TypeHint(types = {ActiveMQConverterLoader.class,
ActiveMQMessageConverterLoader.class,
CamelBaseBulkConverterLoader.class,
CamelXmlJaxpBulkConverterLoader.class,
GenericFileConverterLoader.class,
ResourceConverterLoader.class,
StreamCacheBulkConverterLoader.class},
access = AccessBits.ALL),
@TypeHint(types = ConditionalOnCamelContextAndAutoConfigurationBeans.class, access = AccessBits.ALL),
@TypeHint(types = {RestConfigurationDefinitionAutoConfiguration.class,
RestConfigurationDefinitionProperties.class,
RestConfiguration.class,
SimpleLanguage.class,
ActiveMQComponent.class,
ActiveMQEndpoint.class,
DefaultProcessorFactory.class,
DefaultFactoryFinder.class,
SjmsComponent.class,
Endpoint.class,
ExchangePropertyLanguage.class,
DefaultDeferServiceFactory.class,
DefaultInternalProcessorFactory.class,
ProcessorDefinition.class,
ExchangePropertyLanguageAutoConfiguration.class,
ExchangePropertyLanguageConfiguration.class,
TcpTransportFactory.class,
NIOTransportFactory.class,
NIOSSLTransportFactory.class,
TransportFactory.class,
OpenWireFormatFactory.class,
PooledConnectionFactory.class,
DefaultEvictionPolicy.class,
MarshallerFactory.class},
access = AccessBits.ALL),
@TypeHint(types = {Session.class,
DefaultMessageListenerContainer.class},
access = AccessBits.ALL),
@TypeHint(types = {SpringTransactionPolicy.class,
PlatformTransactionManager.class,
TransactedPolicy.class},
access = AccessBits.ALL),
@TypeHint(typeNames = {
"org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans$OnCamelAutoConfiguration",
"org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans$OnCamelContext"},
access = AccessBits.ALL),
/*
Elasticsearch configuration is copied from the link below. We need to copy it because it is triggered only by ReactiveElasticsearchRepositoriesAutoConfiguration and we are not using it.
https://github.com/spring-projects-experimental/spring-native/blob/master/spring-native-configuration/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchRepositoriesHints.java
*/
@TypeHint(types = {
ElasticsearchException.class,
Script.class,
XContentParser.class,
},
typeNames = {
"org.elasticsearch.client.core.MainResponse",
"org.elasticsearch.client.core.AcknowledgedResponse",
"org.elasticsearch.client.core.CountResponse",
"org.elasticsearch.client.core.MultiTermVectorsResponse",
"org.elasticsearch.index.reindex.BulkByScrollResponse",
"org.elasticsearch.action.admin.indices.refresh.RefreshResponse",
"org.elasticsearch.action.search.SearchResponse",
"org.elasticsearch.action.get.GetResponse",
"org.elasticsearch.action.get.MultiGetResponse",
"org.elasticsearch.action.get.MultiGetShardResponse",
"org.elasticsearch.action.bulk.BulkResponse",
"org.elasticsearch.action.main.MainResponse",
"org.elasticsearch.action.search.MultiSearchResponse",
"org.elasticsearch.action.search.ClearScrollResponse",
}),
@TypeHint(types = {
org.elasticsearch.Version.class
}, access = AccessBits.ALL),
@TypeHint(types = {
org.apache.logging.log4j.message.DefaultFlowMessageFactory.class,
org.apache.logging.log4j.message.ParameterizedMessageFactory.class,
org.apache.logging.log4j.message.ReusableMessageFactory.class
}, access = AccessBits.DECLARED_CONSTRUCTORS),
@TypeHint(typeNames = {
"io.netty.buffer.AbstractByteBufAllocator",
"io.netty.buffer.PooledByteBufAllocator",
"io.netty.channel.ChannelDuplexHandler",
"io.netty.channel.ChannelHandlerAdapter",
"io.netty.channel.ChannelInboundHandlerAdapter",
"io.netty.channel.ChannelInitializer",
"io.netty.channel.ChannelOutboundHandlerAdapter",
"io.netty.channel.CombinedChannelDuplexHandler",
"io.netty.channel.DefaultChannelPipeline$HeadContext",
"io.netty.channel.DefaultChannelPipeline$TailContext",
"io.netty.channel.embedded.EmbeddedChannel",
"io.netty.channel.socket.nio.NioSocketChannel",
"io.netty.handler.codec.ByteToMessageDecoder",
"io.netty.handler.codec.compression.JdkZlibDecoder",
"io.netty.handler.codec.dns.DatagramDnsQueryEncoder",
"io.netty.handler.codec.dns.DnsResponseDecoder",
"io.netty.handler.codec.dns.TcpDnsResponseDecoder",
"io.netty.handler.codec.http.HttpClientCodec",
"io.netty.handler.codec.http.HttpContentDecoder",
"io.netty.handler.codec.http.HttpContentDecompressor",
"io.netty.handler.codec.LengthFieldBasedFrameDecoder",
"io.netty.handler.codec.MessageToByteEncoder",
"io.netty.handler.codec.MessageToMessageDecoder",
"io.netty.handler.timeout.IdleStateHandler",
"io.netty.handler.timeout.ReadTimeoutHandler",
"io.netty.handler.timeout.WriteTimeoutHandler",
"io.netty.resolver.dns.DnsNameResolver",
"io.netty.resolver.dns.DnsNameResolver$1",
"io.netty.resolver.dns.DnsNameResolver$AddressedEnvelopeAdapter",
"io.netty.resolver.dns.DnsNameResolver$DnsResponseHandler",
"io.netty.resolver.InetNameResolver",
"io.netty.resolver.SimpleNameResolver",
"io.netty.util.AbstractChannel",
"io.netty.util.DefaultAttributeMap",
"io.netty.util.ReferenceCountUtil",
"reactor.netty.resources.DefaultPooledConnectionProvider",
"reactor.netty.resources.DefaultPooledConnectionProvider$PooledConnectionAllocator$",
"reactor.netty.resources.DefaultPooledConnectionProvider$PooledConnectionAllocator$PooledConnectionInitializer",
"reactor.netty.resources.PooledConnectionProvider",
"reactor.netty.transport.TransportConfig$TransportChannelInitializer"
})
},
proxies = {
@ProxyHint(types = {XContentParser.class})
},
initialization = {
@InitializationHint(typeNames = {
"org.apache.lucene.util.Constants",
"org.elasticsearch.common.unit.TimeValue",
"org.apache.lucene.util.RamUsageEstimator"
}, initTime = InitializationTime.BUILD)
}
)
public class MySpringNativeApp {
public static void main(String[] args) {
SpringApplication.run(MySpringNativeApp.class, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment