001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.jms.artemis;
018
019import java.util.HashMap;
020import java.util.Map;
021import java.util.UUID;
022import java.util.concurrent.atomic.AtomicInteger;
023
024import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
025
026import org.springframework.boot.autoconfigure.jms.JmsPoolConnectionFactoryProperties;
027import org.springframework.boot.context.properties.ConfigurationProperties;
028import org.springframework.boot.context.properties.NestedConfigurationProperty;
029
030/**
031 * Configuration properties for Artemis.
032 *
033 * @author EddĂș MelĂ©ndez
034 * @author Stephane Nicoll
035 * @since 1.3.0
036 */
037@ConfigurationProperties(prefix = "spring.artemis")
038public class ArtemisProperties {
039
040        /**
041         * Artemis deployment mode, auto-detected by default.
042         */
043        private ArtemisMode mode;
044
045        /**
046         * Artemis broker host.
047         */
048        private String host = "localhost";
049
050        /**
051         * Artemis broker port.
052         */
053        private int port = 61616;
054
055        /**
056         * Login user of the broker.
057         */
058        private String user;
059
060        /**
061         * Login password of the broker.
062         */
063        private String password;
064
065        private final Embedded embedded = new Embedded();
066
067        @NestedConfigurationProperty
068        private final JmsPoolConnectionFactoryProperties pool = new JmsPoolConnectionFactoryProperties();
069
070        public ArtemisMode getMode() {
071                return this.mode;
072        }
073
074        public void setMode(ArtemisMode mode) {
075                this.mode = mode;
076        }
077
078        public String getHost() {
079                return this.host;
080        }
081
082        public void setHost(String host) {
083                this.host = host;
084        }
085
086        public int getPort() {
087                return this.port;
088        }
089
090        public void setPort(int port) {
091                this.port = port;
092        }
093
094        public String getUser() {
095                return this.user;
096        }
097
098        public void setUser(String user) {
099                this.user = user;
100        }
101
102        public String getPassword() {
103                return this.password;
104        }
105
106        public void setPassword(String password) {
107                this.password = password;
108        }
109
110        public Embedded getEmbedded() {
111                return this.embedded;
112        }
113
114        public JmsPoolConnectionFactoryProperties getPool() {
115                return this.pool;
116        }
117
118        /**
119         * Configuration for an embedded Artemis server.
120         */
121        public static class Embedded {
122
123                private static final AtomicInteger serverIdCounter = new AtomicInteger();
124
125                /**
126                 * Server ID. By default, an auto-incremented counter is used.
127                 */
128                private int serverId = serverIdCounter.getAndIncrement();
129
130                /**
131                 * Whether to enable embedded mode if the Artemis server APIs are available.
132                 */
133                private boolean enabled = true;
134
135                /**
136                 * Whether to enable persistent store.
137                 */
138                private boolean persistent;
139
140                /**
141                 * Journal file directory. Not necessary if persistence is turned off.
142                 */
143                private String dataDirectory;
144
145                /**
146                 * Comma-separated list of queues to create on startup.
147                 */
148                private String[] queues = new String[0];
149
150                /**
151                 * Comma-separated list of topics to create on startup.
152                 */
153                private String[] topics = new String[0];
154
155                /**
156                 * Cluster password. Randomly generated on startup by default.
157                 */
158                private String clusterPassword = UUID.randomUUID().toString();
159
160                private boolean defaultClusterPassword = true;
161
162                public int getServerId() {
163                        return this.serverId;
164                }
165
166                public void setServerId(int serverId) {
167                        this.serverId = serverId;
168                }
169
170                public boolean isEnabled() {
171                        return this.enabled;
172                }
173
174                public void setEnabled(boolean enabled) {
175                        this.enabled = enabled;
176                }
177
178                public boolean isPersistent() {
179                        return this.persistent;
180                }
181
182                public void setPersistent(boolean persistent) {
183                        this.persistent = persistent;
184                }
185
186                public String getDataDirectory() {
187                        return this.dataDirectory;
188                }
189
190                public void setDataDirectory(String dataDirectory) {
191                        this.dataDirectory = dataDirectory;
192                }
193
194                public String[] getQueues() {
195                        return this.queues;
196                }
197
198                public void setQueues(String[] queues) {
199                        this.queues = queues;
200                }
201
202                public String[] getTopics() {
203                        return this.topics;
204                }
205
206                public void setTopics(String[] topics) {
207                        this.topics = topics;
208                }
209
210                public String getClusterPassword() {
211                        return this.clusterPassword;
212                }
213
214                public void setClusterPassword(String clusterPassword) {
215                        this.clusterPassword = clusterPassword;
216                        this.defaultClusterPassword = false;
217                }
218
219                public boolean isDefaultClusterPassword() {
220                        return this.defaultClusterPassword;
221                }
222
223                /**
224                 * Creates the minimal transport parameters for an embedded transport
225                 * configuration.
226                 * @return the transport parameters
227                 * @see TransportConstants#SERVER_ID_PROP_NAME
228                 */
229                public Map<String, Object> generateTransportParameters() {
230                        Map<String, Object> parameters = new HashMap<>();
231                        parameters.put(TransportConstants.SERVER_ID_PROP_NAME, getServerId());
232                        return parameters;
233                }
234
235        }
236
237}