Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 805FF200BAD for ; Tue, 25 Oct 2016 15:19:26 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7F18C160AE6; Tue, 25 Oct 2016 13:19:26 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 39311160B04 for ; Tue, 25 Oct 2016 15:19:24 +0200 (CEST) Received: (qmail 39738 invoked by uid 500); 25 Oct 2016 13:19:23 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 38137 invoked by uid 99); 25 Oct 2016 13:19:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 25 Oct 2016 13:19:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 10721F0DC0; Tue, 25 Oct 2016 13:19:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: martyntaylor@apache.org To: commits@activemq.apache.org Date: Tue, 25 Oct 2016 13:19:32 -0000 Message-Id: In-Reply-To: <85a32b9755384bf28e1e4c1b031b17f1@git.apache.org> References: <85a32b9755384bf28e1e4c1b031b17f1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [17/33] activemq-artemis git commit: ARTEMIS-756 Moving Client CDI as a main module archived-at: Tue, 25 Oct 2016 13:19:26 -0000 ARTEMIS-756 Moving Client CDI as a main module Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b23207c0 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b23207c0 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b23207c0 Branch: refs/heads/ARTEMIS-780 Commit: b23207c019ea807791bfde2531c75bd5fa18f952 Parents: 3575972 Author: Clebert Suconic Authored: Mon Oct 24 11:26:32 2016 -0400 Committer: Clebert Suconic Committed: Mon Oct 24 12:12:18 2016 -0400 ---------------------------------------------------------------------- artemis-cdi-client/pom.xml | 121 +++++++++ .../ArtemisClientConfiguration.java | 76 ++++++ .../DefaultArtemisClientConfigurationImpl.java | 95 +++++++ .../client/cdi/extension/AnyLiteral.java | 28 +++ .../cdi/extension/ArtemisClientConfigBean.java | 99 ++++++++ .../ArtemisEmbeddedServerConfigBean.java | 104 ++++++++ .../client/cdi/extension/ArtemisExtension.java | 60 +++++ .../client/cdi/extension/DefaultLiteral.java | 28 +++ .../cdi/factory/ConnectionFactoryProvider.java | 103 ++++++++ .../client/cdi/logger/ActiveMQCDILogger.java | 64 +++++ .../src/main/resources/META-INF/beans.xml | 25 ++ .../javax.enterprise.inject.spi.Extension | 20 ++ .../artemis/cdi/bootstrap/CDIBootstrapTest.java | 73 ++++++ examples/features/standard/cdi/pom.xml | 252 +++++++++++++++++++ examples/features/standard/cdi/readme.md | 86 +++++++ .../artemis/core/example/CDIClientConfig.java | 87 +++++++ .../artemis/core/example/CDIExample.java | 36 +++ .../core/example/CDIMessagingIntegrator.java | 40 +++ .../META-INF/apache-deltaspike.properties | 22 ++ .../cdi/src/main/resources/META-INF/beans.xml | 25 ++ examples/features/standard/pom.xml | 2 + examples/features/sub-modules/cdi/pom.xml | 252 ------------------- examples/features/sub-modules/cdi/readme.md | 86 ------- .../artemis/core/example/CDIClientConfig.java | 87 ------- .../artemis/core/example/CDIExample.java | 36 --- .../core/example/CDIMessagingIntegrator.java | 40 --- .../META-INF/apache-deltaspike.properties | 22 -- .../cdi/src/main/resources/META-INF/beans.xml | 25 -- examples/features/sub-modules/pom.xml | 1 - integration/artemis-cdi-integration/pom.xml | 121 --------- .../ArtemisClientConfiguration.java | 76 ------ .../DefaultArtemisClientConfigurationImpl.java | 95 ------- .../client/cdi/extension/AnyLiteral.java | 28 --- .../cdi/extension/ArtemisClientConfigBean.java | 99 -------- .../ArtemisEmbeddedServerConfigBean.java | 104 -------- .../client/cdi/extension/ArtemisExtension.java | 60 ----- .../client/cdi/extension/DefaultLiteral.java | 28 --- .../cdi/factory/ConnectionFactoryProvider.java | 103 -------- .../client/cdi/logger/ActiveMQCDILogger.java | 64 ----- .../src/main/resources/META-INF/beans.xml | 25 -- .../javax.enterprise.inject.spi.Extension | 20 -- .../artemis/cdi/bootstrap/CDIBootstrapTest.java | 73 ------ pom.xml | 2 +- 43 files changed, 1447 insertions(+), 1446 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/pom.xml ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/pom.xml b/artemis-cdi-client/pom.xml new file mode 100644 index 0000000..0d9f887 --- /dev/null +++ b/artemis-cdi-client/pom.xml @@ -0,0 +1,121 @@ + + + + + + artemis-pom + org.apache.activemq + 1.5.0-SNAPSHOT + .. + + 4.0.0 + + + ${project.basedir}/.. + + + artemis-cdi-client + ActiveMQ Artemis CDI Integration + + + + org.jboss.logging + jboss-logging-processor + provided + true + + + org.jboss.logging + jboss-logging + + + org.apache.activemq + artemis-jms-client + ${project.version} + + + org.apache.activemq + artemis-jms-server + ${project.version} + + + javax.enterprise + cdi-api + + + org.jboss.logmanager + jboss-logmanager + test + + + org.jboss.arquillian.junit + arquillian-junit-container + + + junit + junit + + + + + Weld + + true + + + + org.jboss.weld.se + weld-se + + + org.jboss.arquillian.container + arquillian-weld-embedded + + + + + OWB + + + org.apache.openwebbeans + openwebbeans-impl + + + org.apache.openwebbeans + openwebbeans-spi + + + org.apache.openwebbeans + openwebbeans-resource + + + org.apache.openwebbeans.arquillian + owb-arquillian-standalone + + + org.apache.geronimo.specs + geronimo-annotation_1.2_spec + + + + + http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java new file mode 100644 index 0000000..4bd816c --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.configuration; + +import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory; +import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory; + +public interface ArtemisClientConfiguration { + + String IN_VM_CONNECTOR = InVMConnectorFactory.class.getName(); + String REMOTE_CONNECTOR = NettyConnectorFactory.class.getName(); + + /** + * @return if present, sends a username for the connection + */ + String getUsername(); + + /** + * @return the password for the connection. If username is set, password must be set + */ + String getPassword(); + + /** + * Either url should be set, or host, port, connector factory should be set. + * + * @return if set, will be used in the server locator to look up the server instead of the hostname/port combination + */ + String getUrl(); + + /** + * @return The hostname to connect to + */ + String getHost(); + + /** + * @return the port number to connect to + */ + Integer getPort(); + + /** + * @return the connector factory to use for connections. + */ + String getConnectorFactory(); + + /** + * @return Whether or not to start the embedded broker + */ + boolean startEmbeddedBroker(); + + /** + * @return whether or not this is an HA connection + */ + boolean isHa(); + + /** + * @return whether or not the authentication parameters should be used + */ + boolean hasAuthentication(); +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java new file mode 100644 index 0000000..272e1bf --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.configuration; + +import javax.enterprise.inject.Vetoed; +import java.util.Map; + +@Vetoed +public class DefaultArtemisClientConfigurationImpl implements ArtemisClientConfiguration { + + private String host; + private Integer port; + private String url; + private String username; + private String password; + private boolean ha; + + public DefaultArtemisClientConfigurationImpl() { + } + + public DefaultArtemisClientConfigurationImpl(Map params) { + host = (String) params.get("host"); + port = (Integer) params.get("port"); + url = (String) params.get("url"); + username = (String) params.get("username"); + password = (String) params.get("password"); + Boolean isHa = (Boolean) params.get("ha"); + if (isHa == null) { + isHa = false; + } + ha = isHa; + } + + @Override + public String getHost() { + return host; + } + + @Override + public Integer getPort() { + return port; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public String getConnectorFactory() { + return startEmbeddedBroker() ? IN_VM_CONNECTOR : REMOTE_CONNECTOR; + } + + @Override + public boolean startEmbeddedBroker() { + return host == null && url == null; + } + + @Override + public boolean isHa() { + return ha; + } + + @Override + public boolean hasAuthentication() { + return getUsername() != null && getUsername().length() > 0; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java new file mode 100644 index 0000000..6d0ccaf --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.extension; + +import javax.enterprise.inject.Any; +import javax.enterprise.util.AnnotationLiteral; + +class AnyLiteral extends AnnotationLiteral implements Any { + + static final Any INSTANCE = new AnyLiteral(); +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java new file mode 100644 index 0000000..54f5a7f --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.extension; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.InjectionPoint; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; + +import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; +import org.apache.artemis.client.cdi.configuration.DefaultArtemisClientConfigurationImpl; + +import static java.util.Collections.emptySet; + +class ArtemisClientConfigBean implements Bean { + + @Override + public Class getBeanClass() { + return DefaultArtemisClientConfigurationImpl.class; + } + + @Override + public Set getInjectionPoints() { + return emptySet(); + } + + @Override + public boolean isNullable() { + return false; + } + + @Override + public ArtemisClientConfiguration create(CreationalContext creationalContext) { + return new DefaultArtemisClientConfigurationImpl(); + } + + @Override + public void destroy(ArtemisClientConfiguration configuration, + CreationalContext creationalContext) { + } + + @Override + public Set getTypes() { + Set types = new HashSet<>(); + types.add(DefaultArtemisClientConfigurationImpl.class); + types.add(ArtemisClientConfiguration.class); + return types; + } + + @Override + public Set getQualifiers() { + Set qualifiers = new HashSet<>(); + qualifiers.add(AnyLiteral.INSTANCE); + qualifiers.add(DefaultLiteral.INSTANCE); + return qualifiers; + + } + + @Override + public Class getScope() { + return ApplicationScoped.class; + } + + @Override + public String getName() { + return null; + } + + @Override + public Set> getStereotypes() { + return emptySet(); + } + + @Override + public boolean isAlternative() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java new file mode 100644 index 0000000..5f38240 --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.extension; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.spi.CreationalContext; +import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.InjectionPoint; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.activemq.artemis.api.core.TransportConfiguration; +import org.apache.activemq.artemis.core.config.Configuration; +import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; +import org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory; + +import static java.util.Collections.emptySet; + +public class ArtemisEmbeddedServerConfigBean implements Bean { + + @Override + public Class getBeanClass() { + return ConfigurationImpl.class; + } + + @Override + public Set getInjectionPoints() { + return emptySet(); + } + + @Override + public boolean isNullable() { + return false; + } + + @Override + public Configuration create(CreationalContext creationalContext) { + Map params = new HashMap<>(); + params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); + return new ConfigurationImpl().setSecurityEnabled(false).setPersistenceEnabled(false).setJMXManagementEnabled(false).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params)); + } + + @Override + public void destroy(Configuration configuration, CreationalContext creationalContext) { + } + + @Override + public Set getTypes() { + Set types = new HashSet<>(); + types.add(ConfigurationImpl.class); + types.add(Configuration.class); + return types; + } + + @Override + public Set getQualifiers() { + Set qualifiers = new HashSet<>(); + qualifiers.add(AnyLiteral.INSTANCE); + qualifiers.add(DefaultLiteral.INSTANCE); + return qualifiers; + + } + + @Override + public Class getScope() { + return ApplicationScoped.class; + } + + @Override + public String getName() { + return null; + } + + @Override + public Set> getStereotypes() { + return emptySet(); + } + + @Override + public boolean isAlternative() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java new file mode 100644 index 0000000..d9a0d54 --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.extension; + +import javax.enterprise.event.Observes; +import javax.enterprise.inject.spi.AfterBeanDiscovery; +import javax.enterprise.inject.spi.Extension; +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import org.apache.activemq.artemis.core.config.Configuration; +import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; +import org.apache.artemis.client.cdi.logger.ActiveMQCDILogger; + +public class ArtemisExtension implements Extension { + + private boolean foundEmbeddedConfig = false; + private boolean foundConfiguration = false; + + void foundClientConfig(@Observes ProcessAnnotatedType pat) { + ActiveMQCDILogger.LOGGER.discoveredConfiguration(pat); + foundConfiguration = true; + } + + void foundEmbeddedConfig(@Observes ProcessAnnotatedType pat) { + ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(pat); + foundEmbeddedConfig = true; + } + + void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery) { + if (!foundConfiguration) { + afterBeanDiscovery.addBean(new ArtemisClientConfigBean()); + } else { + ActiveMQCDILogger.LOGGER.notUsingDefaultConfiguration(); + } + if (!foundEmbeddedConfig) { + afterBeanDiscovery.addBean(new ArtemisEmbeddedServerConfigBean()); + } else { + ActiveMQCDILogger.LOGGER.notUsingDefaultClientConfiguration(); + } + + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java new file mode 100644 index 0000000..2280535 --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.extension; + +import javax.enterprise.inject.Default; +import javax.enterprise.util.AnnotationLiteral; + +class DefaultLiteral extends AnnotationLiteral implements Default { + + static final Default INSTANCE = new DefaultLiteral(); +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java new file mode 100644 index 0000000..b249474 --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.factory; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.jms.JMSContext; +import java.util.HashMap; +import java.util.Map; + +import org.apache.activemq.artemis.api.core.TransportConfiguration; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.api.jms.JMSFactoryType; +import org.apache.activemq.artemis.core.config.Configuration; +import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; +import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.ActiveMQServers; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl; +import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; + +@ApplicationScoped +public class ConnectionFactoryProvider { + + @Produces + @ApplicationScoped + private ActiveMQConnectionFactory activeMQConnectionFactory; + + @Inject + private ArtemisClientConfiguration configuration; + + @Inject + private Configuration embeddedConfiguration; + + @PostConstruct + public void setupConnection() { + if (configuration.startEmbeddedBroker()) { + try { + ActiveMQServer activeMQServer = ActiveMQServers.newActiveMQServer(embeddedConfiguration, false); + JMSServerManagerImpl jmsServerManager = new JMSServerManagerImpl(activeMQServer); + jmsServerManager.start(); + } catch (Exception e) { + throw new RuntimeException("Unable to start embedded JMS", e); + } + } + + try { + this.activeMQConnectionFactory = createConnectionFactory(); + } catch (Exception e) { + throw new RuntimeException("Unable to connect to remote server", e); + } + } + + @Produces + @ApplicationScoped + public JMSContext createJMSContext() { + return this.activeMQConnectionFactory.createContext(); + } + + private ActiveMQConnectionFactory createConnectionFactory() throws Exception { + Map params = new HashMap<>(); + params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); + final ActiveMQConnectionFactory activeMQConnectionFactory; + if (configuration.getUrl() != null) { + activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null); + } else { + if (configuration.getHost() != null) { + params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost()); + params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort()); + } + if (configuration.isHa()) { + activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); + } else { + activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); + } + } + if (configuration.hasAuthentication()) { + activeMQConnectionFactory.setUser(configuration.getUsername()); + activeMQConnectionFactory.setPassword(configuration.getPassword()); + } + // The CF will probably be GCed since it was injected, so we disable the finalize check + return activeMQConnectionFactory.disableFinalizeChecks(); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java new file mode 100644 index 0000000..fd2f7e7 --- /dev/null +++ b/artemis-cdi-client/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.artemis.client.cdi.logger; + +import javax.enterprise.inject.spi.ProcessAnnotatedType; + +import org.jboss.logging.BasicLogger; +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.LogMessage; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; + +/** + * Logger code 57 + * + * each message id must be 6 digits long starting with 57, the 3rd digit donates the level so + * + * INF0 1 + * WARN 2 + * DEBUG 3 + * ERROR 4 + * TRACE 5 + * FATAL 6 + * + * so an INFO message would be 571000 to 571999 + */ +@MessageLogger(projectCode = "AMQ") +public interface ActiveMQCDILogger extends BasicLogger { + + ActiveMQCDILogger LOGGER = Logger.getMessageLogger(ActiveMQCDILogger.class, ActiveMQCDILogger.class.getPackage().getName()); + + @LogMessage + @Message(id = 571000, value = "Discovered configuration class {0}", format = Message.Format.MESSAGE_FORMAT) + void discoveredConfiguration(ProcessAnnotatedType pat); + + @LogMessage + @Message(id = 571001, value = "Discovered client configuration class {0}", format = Message.Format.MESSAGE_FORMAT) + void discoveredClientConfiguration(ProcessAnnotatedType pat); + + @LogMessage(level = Logger.Level.DEBUG) + @Message(id = 573000, value = "Configuration found, not using built in configuration") + void notUsingDefaultConfiguration(); + + @LogMessage(level = Logger.Level.DEBUG) + @Message(id = 573001, value = "Configuration found, not using built in configuration") + void notUsingDefaultClientConfiguration(); +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/resources/META-INF/beans.xml b/artemis-cdi-client/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..b6f51f1 --- /dev/null +++ b/artemis-cdi-client/src/main/resources/META-INF/beans.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/artemis-cdi-client/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension new file mode 100644 index 0000000..81282d4 --- /dev/null +++ b/artemis-cdi-client/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +org.apache.artemis.client.cdi.extension.ArtemisExtension \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/artemis-cdi-client/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java ---------------------------------------------------------------------- diff --git a/artemis-cdi-client/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java b/artemis-cdi-client/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java new file mode 100644 index 0000000..84afda7 --- /dev/null +++ b/artemis-cdi-client/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.activemq.artemis.cdi.bootstrap; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.spi.Extension; +import javax.inject.Inject; +import javax.jms.JMSContext; +import javax.jms.Queue; + +import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; +import org.apache.artemis.client.cdi.configuration.DefaultArtemisClientConfigurationImpl; +import org.apache.artemis.client.cdi.extension.ArtemisExtension; +import org.apache.artemis.client.cdi.factory.ConnectionFactoryProvider; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +public class CDIBootstrapTest { + + @Deployment + public static Archive createArchive() { + return ShrinkWrap.create(JavaArchive.class).addAsServiceProviderAndClasses(Extension.class, ArtemisExtension.class).addClasses(NativeConfig.class, ConnectionFactoryProvider.class).addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + } + + @Inject + private JMSContext jmsContext; + + @Test + public void shouldStartJMS() throws Exception { + String body = "This is a test"; + Queue queue = jmsContext.createQueue("test"); + jmsContext.createProducer().send(queue, body); + String receivedBody = jmsContext.createConsumer(queue).receiveBody(String.class, 5000); + Assert.assertNotNull(receivedBody); + assertEquals(body, receivedBody); + } + + @ApplicationScoped + public static class NativeConfig extends DefaultArtemisClientConfigurationImpl { + + @Override + public String getConnectorFactory() { + return ArtemisClientConfiguration.IN_VM_CONNECTOR; + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/pom.xml b/examples/features/standard/cdi/pom.xml new file mode 100644 index 0000000..567bef4 --- /dev/null +++ b/examples/features/standard/cdi/pom.xml @@ -0,0 +1,252 @@ + + + + + 4.0.0 + + + org.apache.activemq.examples.broker + jms-examples + 1.5.0-SNAPSHOT + + + artemis-cdi-example + jar + ActiveMQ Artemis CDI Example + + + ${project.basedir}/../../../.. + 1.7.1 + + + + + org.apache.activemq + artemis-server + ${project.version} + + + org.apache.activemq + artemis-core-client + ${project.version} + + + org.apache.activemq + artemis-commons + ${project.version} + + + io.netty + netty-all + ${netty.version} + + + org.apache.geronimo.specs + geronimo-jms_2.0_spec + + + org.apache.activemq + artemis-cdi-client + ${project.version} + + + org.apache.deltaspike.cdictrl + deltaspike-cdictrl-api + ${deltaspike.version} + + + javax.enterprise + cdi-api + + + org.apache.deltaspike.core + deltaspike-core-api + ${deltaspike.version} + + + org.apache.deltaspike.core + deltaspike-core-impl + ${deltaspike.version} + + + + + Weld + + true + + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + + org.apache.activemq.examples.broker:artemis-cdi-example:${project.version} + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + runClient + + runClient + + + org.apache.activemq.artemis.core.example.CDIExample + + + + + + org.apache.activemq.examples.broker + artemis-cdi-example + ${project.version} + + + org.jboss.weld.se + weld-se + ${weld.version} + + + org.apache.deltaspike.cdictrl + deltaspike-cdictrl-weld + ${deltaspike.version} + + + + + + + + OWB + + + + org.apache.activemq + artemis-maven-plugin + + + create0 + + create + + + + org.apache.activemq.examples.broker:artemis-cdi-example:${project.version} + + + ${basedir}/target/server0 + ${basedir}/target/classes/activemq/server0 + + + + start0 + + cli + + + ${noServer} + true + ${basedir}/target/server0 + tcp://localhost:61616 + + run + + server0 + + + + runClient + + runClient + + + org.apache.activemq.artemis.core.example.CDIExample + + + + + + org.apache.activemq.examples.broker + artemis-cdi-example + ${project.version} + + + javax.enterprise + cdi-api + ${cdi-api.version} + + + org.apache.openwebbeans + openwebbeans-impl + ${owb.version} + + + org.apache.openwebbeans + openwebbeans-spi + ${owb.version} + + + org.apache.openwebbeans + openwebbeans-resource + ${owb.version} + + + org.apache.geronimo.specs + geronimo-annotation_1.2_spec + ${geronimo-annotation_1.2_spec.version} + + + org.apache.deltaspike.cdictrl + deltaspike-cdictrl-owb + ${deltaspike.version} + + + + + + + + http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/readme.md ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/readme.md b/examples/features/standard/cdi/readme.md new file mode 100644 index 0000000..7e981ca --- /dev/null +++ b/examples/features/standard/cdi/readme.md @@ -0,0 +1,86 @@ + +# ActiveMQ Artemis CDI Integration Example + +This is a simple example that demonstrates how to use CDI to integrate with ActiveMQ Artemis on the client side. It is designed mainly for connecting to a remote broker rather than embedding within your application. + +## Configuring the connection + +While the integration provides an out of the box solution for configuration with some sensible defaults, the values should be configurable. This example leverages [Apache DeltaSpike](https://deltaspike.apache.org) to configure the connectivity. It overrides the username, password and URL for the broker. The configuration hard codes the connector class. This configuration class is a standard CDI bean. + +``` +@ApplicationScoped +public class CDIClientConfig implements ArtemisClientConfiguration { + @Inject + @ConfigProperty(name = "username") + private String username; + + @Inject + @ConfigProperty(name = "password") + private String password; + + @Inject + @ConfigProperty(name = "url") + private String url; + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public String getConnectorFactory() { + return "org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory"; + } +} +``` + +## Setup and Tear Down + +For the example, we leverage DeltaSpike's Container Control to start and stop the container. It is implemented within the main method, and is done in a way to make this work for both Weld and OpenWebBeans. + +## Sending and Receiving Messages + +The key to how the CDI integration works is the built in beans. It provides two out of the box - a `ConnectionFactory` and a `JMSContext`. Most operations should be performed against the JMS 2.0 simplified API using `JMSContext`. The example does this via an observer method, but can be done anywhere. + +``` +@ApplicationScoped +public class CDIMessagingIntegrator { + @Inject + private JMSContext context; + public void init(@Observes @Initialized(ApplicationScoped.class) Object obj) { + String body = "This is a test"; + Queue queue = context.createQueue("test"); + context.createProducer().send(queue, body); + String receivedBody = context.createConsumer(queue).receiveBody(String.class, 5000); + System.out.println("Received a message "+receivedBody); + } +} +``` \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java new file mode 100644 index 0000000..93037ca --- /dev/null +++ b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.activemq.artemis.core.example; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; + +import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; +import org.apache.deltaspike.core.api.config.ConfigProperty; + +@ApplicationScoped +public class CDIClientConfig implements ArtemisClientConfiguration { + @Inject + @ConfigProperty(name = "username") + private String username; + + @Inject + @ConfigProperty(name = "password") + private String password; + + @Inject + @ConfigProperty(name = "url") + private String url; + + + @Override + public String getUsername() { + return username; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public String getHost() { + return null; + } + + @Override + public Integer getPort() { + return null; + } + + @Override + public String getConnectorFactory() { + return "org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory"; + } + + @Override + public boolean startEmbeddedBroker() { + return false; + } + + @Override + public boolean isHa() { + return false; + } + + @Override + public boolean hasAuthentication() { + return false; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIExample.java ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIExample.java b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIExample.java new file mode 100644 index 0000000..bbbf49c --- /dev/null +++ b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIExample.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.activemq.artemis.core.example; + +import org.apache.deltaspike.cdise.api.CdiContainer; +import org.apache.deltaspike.cdise.api.CdiContainerLoader; + +/** + * A simple example using DeltaSpike CDI Control to connect to an external broker + */ +public class CDIExample { + + public static void main(final String[] args) throws Exception { + CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer(); + cdiContainer.boot(); + + cdiContainer.shutdown(); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIMessagingIntegrator.java ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIMessagingIntegrator.java b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIMessagingIntegrator.java new file mode 100644 index 0000000..a3b530c --- /dev/null +++ b/examples/features/standard/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIMessagingIntegrator.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.activemq.artemis.core.example; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.Initialized; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.jms.JMSContext; +import javax.jms.Queue; + +@ApplicationScoped +public class CDIMessagingIntegrator { + @Inject + private JMSContext context; + public void init(@Observes @Initialized(ApplicationScoped.class) Object obj) { + String body = "This is a test"; + Queue queue = context.createQueue("test"); + context.createProducer().send(queue, body); + String receivedBody = context.createConsumer(queue).receiveBody(String.class, 5000); + System.out.println("Received a message " + receivedBody); + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/src/main/resources/META-INF/apache-deltaspike.properties ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/src/main/resources/META-INF/apache-deltaspike.properties b/examples/features/standard/cdi/src/main/resources/META-INF/apache-deltaspike.properties new file mode 100644 index 0000000..eb75483 --- /dev/null +++ b/examples/features/standard/cdi/src/main/resources/META-INF/apache-deltaspike.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +username=guest +password=guest +url=tcp://localhost:61616 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/cdi/src/main/resources/META-INF/beans.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/cdi/src/main/resources/META-INF/beans.xml b/examples/features/standard/cdi/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..b6f51f1 --- /dev/null +++ b/examples/features/standard/cdi/src/main/resources/META-INF/beans.xml @@ -0,0 +1,25 @@ + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/standard/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/standard/pom.xml b/examples/features/standard/pom.xml index 610b289..84c4197 100644 --- a/examples/features/standard/pom.xml +++ b/examples/features/standard/pom.xml @@ -43,6 +43,7 @@ under the License. bridge browser + cdi client-kickoff consumer-rate-limit dead-letter @@ -104,6 +105,7 @@ under the License. bridge browser + cdi client-kickoff consumer-rate-limit dead-letter http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/sub-modules/cdi/pom.xml ---------------------------------------------------------------------- diff --git a/examples/features/sub-modules/cdi/pom.xml b/examples/features/sub-modules/cdi/pom.xml deleted file mode 100644 index 30580d5..0000000 --- a/examples/features/sub-modules/cdi/pom.xml +++ /dev/null @@ -1,252 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.modules - broker-modules - 1.5.0-SNAPSHOT - - - artemis-cdi-example - jar - ActiveMQ Artemis CDI Example - - - ${project.basedir}/../../../.. - 1.7.1 - - - - - org.apache.activemq - artemis-server - ${project.version} - - - org.apache.activemq - artemis-core-client - ${project.version} - - - org.apache.activemq - artemis-commons - ${project.version} - - - io.netty - netty-all - ${netty.version} - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - org.apache.activemq - artemis-cdi-client - ${project.version} - - - org.apache.deltaspike.cdictrl - deltaspike-cdictrl-api - ${deltaspike.version} - - - javax.enterprise - cdi-api - - - org.apache.deltaspike.core - deltaspike-core-api - ${deltaspike.version} - - - org.apache.deltaspike.core - deltaspike-core-impl - ${deltaspike.version} - - - - - Weld - - true - - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - - org.apache.activemq.examples.modules:artemis-cdi-example:${project.version} - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - start0 - - cli - - - ${noServer} - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - runClient - - runClient - - - org.apache.activemq.artemis.core.example.CDIExample - - - - - - org.apache.activemq.examples.modules - artemis-cdi-example - ${project.version} - - - org.jboss.weld.se - weld-se - ${weld.version} - - - org.apache.deltaspike.cdictrl - deltaspike-cdictrl-weld - ${deltaspike.version} - - - - - - - - OWB - - - - org.apache.activemq - artemis-maven-plugin - - - create0 - - create - - - - org.apache.activemq.examples.modules:artemis-cdi-example:${project.version} - - - ${basedir}/target/server0 - ${basedir}/target/classes/activemq/server0 - - - - start0 - - cli - - - ${noServer} - true - ${basedir}/target/server0 - tcp://localhost:61616 - - run - - server0 - - - - runClient - - runClient - - - org.apache.activemq.artemis.core.example.CDIExample - - - - - - org.apache.activemq.examples.modules - artemis-cdi-example - ${project.version} - - - javax.enterprise - cdi-api - ${cdi-api.version} - - - org.apache.openwebbeans - openwebbeans-impl - ${owb.version} - - - org.apache.openwebbeans - openwebbeans-spi - ${owb.version} - - - org.apache.openwebbeans - openwebbeans-resource - ${owb.version} - - - org.apache.geronimo.specs - geronimo-annotation_1.2_spec - ${geronimo-annotation_1.2_spec.version} - - - org.apache.deltaspike.cdictrl - deltaspike-cdictrl-owb - ${deltaspike.version} - - - - - - - - http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/sub-modules/cdi/readme.md ---------------------------------------------------------------------- diff --git a/examples/features/sub-modules/cdi/readme.md b/examples/features/sub-modules/cdi/readme.md deleted file mode 100644 index 7e981ca..0000000 --- a/examples/features/sub-modules/cdi/readme.md +++ /dev/null @@ -1,86 +0,0 @@ - -# ActiveMQ Artemis CDI Integration Example - -This is a simple example that demonstrates how to use CDI to integrate with ActiveMQ Artemis on the client side. It is designed mainly for connecting to a remote broker rather than embedding within your application. - -## Configuring the connection - -While the integration provides an out of the box solution for configuration with some sensible defaults, the values should be configurable. This example leverages [Apache DeltaSpike](https://deltaspike.apache.org) to configure the connectivity. It overrides the username, password and URL for the broker. The configuration hard codes the connector class. This configuration class is a standard CDI bean. - -``` -@ApplicationScoped -public class CDIClientConfig implements ArtemisClientConfiguration { - @Inject - @ConfigProperty(name = "username") - private String username; - - @Inject - @ConfigProperty(name = "password") - private String password; - - @Inject - @ConfigProperty(name = "url") - private String url; - - @Override - public String getUsername() { - return username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getUrl() { - return url; - } - - @Override - public String getConnectorFactory() { - return "org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory"; - } -} -``` - -## Setup and Tear Down - -For the example, we leverage DeltaSpike's Container Control to start and stop the container. It is implemented within the main method, and is done in a way to make this work for both Weld and OpenWebBeans. - -## Sending and Receiving Messages - -The key to how the CDI integration works is the built in beans. It provides two out of the box - a `ConnectionFactory` and a `JMSContext`. Most operations should be performed against the JMS 2.0 simplified API using `JMSContext`. The example does this via an observer method, but can be done anywhere. - -``` -@ApplicationScoped -public class CDIMessagingIntegrator { - @Inject - private JMSContext context; - public void init(@Observes @Initialized(ApplicationScoped.class) Object obj) { - String body = "This is a test"; - Queue queue = context.createQueue("test"); - context.createProducer().send(queue, body); - String receivedBody = context.createConsumer(queue).receiveBody(String.class, 5000); - System.out.println("Received a message "+receivedBody); - } -} -``` \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b23207c0/examples/features/sub-modules/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java ---------------------------------------------------------------------- diff --git a/examples/features/sub-modules/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java b/examples/features/sub-modules/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java deleted file mode 100644 index 93037ca..0000000 --- a/examples/features/sub-modules/cdi/src/main/java/org/apache/activemq/artemis/core/example/CDIClientConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.activemq.artemis.core.example; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; - -import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration; -import org.apache.deltaspike.core.api.config.ConfigProperty; - -@ApplicationScoped -public class CDIClientConfig implements ArtemisClientConfiguration { - @Inject - @ConfigProperty(name = "username") - private String username; - - @Inject - @ConfigProperty(name = "password") - private String password; - - @Inject - @ConfigProperty(name = "url") - private String url; - - - @Override - public String getUsername() { - return username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getUrl() { - return url; - } - - @Override - public String getHost() { - return null; - } - - @Override - public Integer getPort() { - return null; - } - - @Override - public String getConnectorFactory() { - return "org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory"; - } - - @Override - public boolean startEmbeddedBroker() { - return false; - } - - @Override - public boolean isHa() { - return false; - } - - @Override - public boolean hasAuthentication() { - return false; - } -}