001/* 002 * Copyright 2012-2016 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; 018 019import org.springframework.boot.context.properties.ConfigurationProperties; 020 021/** 022 * Configuration properties for JMS. 023 * 024 * @author Greg Turnquist 025 * @author Phillip Webb 026 * @author Stephane Nicoll 027 */ 028@ConfigurationProperties(prefix = "spring.jms") 029public class JmsProperties { 030 031 /** 032 * Specify if the default destination type is topic. 033 */ 034 private boolean pubSubDomain = false; 035 036 /** 037 * Connection factory JNDI name. When set, takes precedence to others connection 038 * factory auto-configurations. 039 */ 040 private String jndiName; 041 042 private final Listener listener = new Listener(); 043 044 private final Template template = new Template(); 045 046 public boolean isPubSubDomain() { 047 return this.pubSubDomain; 048 } 049 050 public void setPubSubDomain(boolean pubSubDomain) { 051 this.pubSubDomain = pubSubDomain; 052 } 053 054 public String getJndiName() { 055 return this.jndiName; 056 } 057 058 public void setJndiName(String jndiName) { 059 this.jndiName = jndiName; 060 } 061 062 public Listener getListener() { 063 return this.listener; 064 } 065 066 public Template getTemplate() { 067 return this.template; 068 } 069 070 public static class Listener { 071 072 /** 073 * Start the container automatically on startup. 074 */ 075 private boolean autoStartup = true; 076 077 /** 078 * Acknowledge mode of the container. By default, the listener is transacted with 079 * automatic acknowledgment. 080 */ 081 private AcknowledgeMode acknowledgeMode; 082 083 /** 084 * Minimum number of concurrent consumers. 085 */ 086 private Integer concurrency; 087 088 /** 089 * Maximum number of concurrent consumers. 090 */ 091 private Integer maxConcurrency; 092 093 public boolean isAutoStartup() { 094 return this.autoStartup; 095 } 096 097 public void setAutoStartup(boolean autoStartup) { 098 this.autoStartup = autoStartup; 099 } 100 101 public AcknowledgeMode getAcknowledgeMode() { 102 return this.acknowledgeMode; 103 } 104 105 public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { 106 this.acknowledgeMode = acknowledgeMode; 107 } 108 109 public Integer getConcurrency() { 110 return this.concurrency; 111 } 112 113 public void setConcurrency(Integer concurrency) { 114 this.concurrency = concurrency; 115 } 116 117 public Integer getMaxConcurrency() { 118 return this.maxConcurrency; 119 } 120 121 public void setMaxConcurrency(Integer maxConcurrency) { 122 this.maxConcurrency = maxConcurrency; 123 } 124 125 public String formatConcurrency() { 126 if (this.concurrency == null) { 127 return (this.maxConcurrency != null ? "1-" + this.maxConcurrency : null); 128 } 129 return (this.maxConcurrency != null 130 ? this.concurrency + "-" + this.maxConcurrency 131 : String.valueOf(this.concurrency)); 132 } 133 134 } 135 136 public static class Template { 137 138 /** 139 * Default destination to use on send/receive operations that do not have a 140 * destination parameter. 141 */ 142 private String defaultDestination; 143 144 /** 145 * Delivery delay to use for send calls in milliseconds. 146 */ 147 private Long deliveryDelay; 148 149 /** 150 * Delivery mode. Enable QoS when set. 151 */ 152 private DeliveryMode deliveryMode; 153 154 /** 155 * Priority of a message when sending. Enable QoS when set. 156 */ 157 private Integer priority; 158 159 /** 160 * Time-to-live of a message when sending in milliseconds. Enable QoS when set. 161 */ 162 private Long timeToLive; 163 164 /** 165 * Enable explicit QoS when sending a message. When enabled, the delivery mode, 166 * priority and time-to-live properties will be used when sending a message. QoS 167 * is automatically enabled when at least one of those settings is customized. 168 */ 169 private Boolean qosEnabled; 170 171 /** 172 * Timeout to use for receive calls in milliseconds. 173 */ 174 private Long receiveTimeout; 175 176 public String getDefaultDestination() { 177 return this.defaultDestination; 178 } 179 180 public void setDefaultDestination(String defaultDestination) { 181 this.defaultDestination = defaultDestination; 182 } 183 184 public Long getDeliveryDelay() { 185 return this.deliveryDelay; 186 } 187 188 public void setDeliveryDelay(Long deliveryDelay) { 189 this.deliveryDelay = deliveryDelay; 190 } 191 192 public DeliveryMode getDeliveryMode() { 193 return this.deliveryMode; 194 } 195 196 public void setDeliveryMode(DeliveryMode deliveryMode) { 197 this.deliveryMode = deliveryMode; 198 } 199 200 public Integer getPriority() { 201 return this.priority; 202 } 203 204 public void setPriority(Integer priority) { 205 this.priority = priority; 206 } 207 208 public Long getTimeToLive() { 209 return this.timeToLive; 210 } 211 212 public void setTimeToLive(Long timeToLive) { 213 this.timeToLive = timeToLive; 214 } 215 216 public boolean determineQosEnabled() { 217 if (this.qosEnabled != null) { 218 return this.qosEnabled; 219 } 220 return (getDeliveryMode() != null || getPriority() != null 221 || getTimeToLive() != null); 222 } 223 224 public Boolean getQosEnabled() { 225 return this.qosEnabled; 226 } 227 228 public void setQosEnabled(Boolean qosEnabled) { 229 this.qosEnabled = qosEnabled; 230 } 231 232 public Long getReceiveTimeout() { 233 return this.receiveTimeout; 234 } 235 236 public void setReceiveTimeout(Long receiveTimeout) { 237 this.receiveTimeout = receiveTimeout; 238 } 239 240 } 241 242 /** 243 * Translate the acknowledge modes defined on the {@link javax.jms.Session}. 244 * 245 * <p> 246 * {@link javax.jms.Session#SESSION_TRANSACTED} is not defined as we take care of this 247 * already via a call to {@code setSessionTransacted}. 248 */ 249 public enum AcknowledgeMode { 250 251 /** 252 * Messages sent or received from the session are automatically acknowledged. This 253 * is the simplest mode and enables once-only message delivery guarantee. 254 */ 255 AUTO(1), 256 257 /** 258 * Messages are acknowledged once the message listener implementation has called 259 * {@link javax.jms.Message#acknowledge()}. This mode gives the application 260 * (rather than the JMS provider) complete control over message acknowledgement. 261 */ 262 CLIENT(2), 263 264 /** 265 * Similar to auto acknowledgment except that said acknowledgment is lazy. As a 266 * consequence, the messages might be delivered more than once. This mode enables 267 * at-least-once message delivery guarantee. 268 */ 269 DUPS_OK(3); 270 271 private final int mode; 272 273 AcknowledgeMode(int mode) { 274 this.mode = mode; 275 } 276 277 public int getMode() { 278 return this.mode; 279 } 280 281 } 282 283 public enum DeliveryMode { 284 285 /** 286 * Does not require that the message be logged to stable storage. This is the 287 * lowest-overhead delivery mode but can lead to lost of message if the broker 288 * goes down. 289 */ 290 NON_PERSISTENT(1), 291 292 /* 293 * Instructs the JMS provider to log the message to stable storage as part of the 294 * client's send operation. 295 */ 296 PERSISTENT(2); 297 298 private final int value; 299 300 DeliveryMode(int value) { 301 this.value = value; 302 } 303 304 public int getValue() { 305 return this.value; 306 } 307 308 } 309 310}