View | Details | Raw Unified | Return to bug 50666
Collapse All | Expand All

(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 341-346 Link Here
341
jms_dest_setup=Setup
341
jms_dest_setup=Setup
342
jms_dest_setup_dynamic=Each sample
342
jms_dest_setup_dynamic=Each sample
343
jms_dest_setup_static=At startup
343
jms_dest_setup_static=At startup
344
jms_durable_subscription_id=Durable Subscription ID
344
jms_error_msg=Object message should read from an external file. Text input is currently selected, please remember to change it.
345
jms_error_msg=Object message should read from an external file. Text input is currently selected, please remember to change it.
345
jms_file=File
346
jms_file=File
346
jms_initial_context_factory=Initial Context Factory
347
jms_initial_context_factory=Initial Context Factory
(-)src/protocol/jms/org/apache/jmeter/protocol/jms/client/ReceiveSubscriber.java (-4 / +38 lines)
Lines 29-34 Link Here
29
import javax.jms.MessageConsumer;
29
import javax.jms.MessageConsumer;
30
import javax.jms.MessageListener;
30
import javax.jms.MessageListener;
31
import javax.jms.Session;
31
import javax.jms.Session;
32
import javax.jms.Topic;
32
import javax.naming.Context;
33
import javax.naming.Context;
33
import javax.naming.NamingException;
34
import javax.naming.NamingException;
34
35
Lines 81-94 Link Here
81
     */
82
     */
82
    public ReceiveSubscriber(boolean useProps, 
83
    public ReceiveSubscriber(boolean useProps, 
83
            String initialContextFactory, String providerUrl, String connfactory, String destinationName,
84
            String initialContextFactory, String providerUrl, String connfactory, String destinationName,
84
            boolean useAuth, 
85
            String durableSubscriptionId, boolean useAuth, 
85
            String securityPrincipal, String securityCredentials) throws NamingException, JMSException {
86
            String securityPrincipal, String securityCredentials) throws NamingException, JMSException {
86
        Context ctx = InitialContextFactory.getContext(useProps, 
87
        Context ctx = InitialContextFactory.getContext(useProps, 
87
                initialContextFactory, providerUrl, useAuth, securityPrincipal, securityCredentials);
88
                initialContextFactory, providerUrl, useAuth, securityPrincipal, securityCredentials);
88
        CONN = Utils.getConnection(ctx, connfactory);
89
        CONN = Utils.getConnection(ctx, connfactory);
89
        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
90
        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
90
        Destination dest = Utils.lookupDestination(ctx, destinationName);
91
        Destination dest = Utils.lookupDestination(ctx, destinationName);
91
        SUBSCRIBER = SESSION.createConsumer(dest);
92
       	SUBSCRIBER = createSubscriber(SESSION, dest, durableSubscriptionId);
92
        queue = null;
93
        queue = null;
93
        log.debug("<init> complete");
94
        log.debug("<init> complete");
94
    }
95
    }
Lines 114-127 Link Here
114
     */
115
     */
115
    public ReceiveSubscriber(int queueSize, boolean useProps, 
116
    public ReceiveSubscriber(int queueSize, boolean useProps, 
116
            String initialContextFactory, String providerUrl, String connfactory, String destinationName,
117
            String initialContextFactory, String providerUrl, String connfactory, String destinationName,
117
            boolean useAuth, 
118
            String durableSubscriptionId, boolean useAuth, 
118
            String securityPrincipal, String securityCredentials) throws NamingException, JMSException {
119
            String securityPrincipal, String securityCredentials) throws NamingException, JMSException {
119
        Context ctx = InitialContextFactory.getContext(useProps, 
120
        Context ctx = InitialContextFactory.getContext(useProps, 
120
                initialContextFactory, providerUrl, useAuth, securityPrincipal, securityCredentials);
121
                initialContextFactory, providerUrl, useAuth, securityPrincipal, securityCredentials);
121
        CONN = Utils.getConnection(ctx, connfactory);
122
        CONN = Utils.getConnection(ctx, connfactory);
122
        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
123
        SESSION = CONN.createSession(false, Session.AUTO_ACKNOWLEDGE);
123
        Destination dest = Utils.lookupDestination(ctx, destinationName);
124
        Destination dest = Utils.lookupDestination(ctx, destinationName);
124
        SUBSCRIBER = SESSION.createConsumer(dest);
125
        SUBSCRIBER = createSubscriber(SESSION, dest, durableSubscriptionId);
125
        if (queueSize <=0) {
126
        if (queueSize <=0) {
126
            queue = new LinkedBlockingQueue<Message>();
127
            queue = new LinkedBlockingQueue<Message>();
127
        } else {
128
        } else {
Lines 130-135 Link Here
130
        SUBSCRIBER.setMessageListener(this);
131
        SUBSCRIBER.setMessageListener(this);
131
        log.debug("<init> complete");
132
        log.debug("<init> complete");
132
    }
133
    }
134
    
135
    /**
136
     * Return a simple MessageConsumer or a TopicSubscriber (as a durable subscription)
137
     * @param session
138
     * 				JMS session	
139
     * @param destination
140
     * 				JMS destination, can be either topic or queue
141
     * @param durableSubscriptionId 
142
     * 				If neither empty nor null, this means that a durable 
143
     * 				subscription will be used
144
     * @return
145
     * @throws JMSException
146
     */
147
    private MessageConsumer createSubscriber(Session session, 
148
    		Destination destination, String durableSubscriptionId) throws JMSException {
149
    	if (isEmpty(durableSubscriptionId)) {
150
        	return  session.createConsumer(destination);
151
        } else {
152
        	return session.createDurableSubscriber((Topic) destination, durableSubscriptionId); 
153
        }	
154
    }
133
155
134
    /**
156
    /**
135
     * Calls Connection.start() to begin receiving inbound messages.
157
     * Calls Connection.start() to begin receiving inbound messages.
Lines 204-207 Link Here
204
            log.warn("Could not add message to queue");
226
            log.warn("Could not add message to queue");
205
        }
227
        }
206
    }
228
    }
229
    
230
    
231
    /**
232
     * Checks whether string is empty
233
     * 
234
     * @param s1
235
     * @return True if input is null, an empty string, 
236
     * 				or a white space-only string
237
     */
238
    private boolean isEmpty(String s1) {
239
    	return (s1 == null || s1.trim().equals(""));
240
    }
207
}
241
}
(-)src/protocol/jms/org/apache/jmeter/protocol/jms/control/gui/JMSSubscriberGui.java (+7 lines)
Lines 58-63 Link Here
58
58
59
    private final JLabeledTextField jmsDestination =
59
    private final JLabeledTextField jmsDestination =
60
        new JLabeledTextField(JMeterUtils.getResString("jms_topic")); // $NON-NLS-1$
60
        new JLabeledTextField(JMeterUtils.getResString("jms_topic")); // $NON-NLS-1$
61
    
62
    private final JLabeledTextField jmsDurableSubscriptionId =
63
        new JLabeledTextField(JMeterUtils.getResString("jms_durable_subscription_id")); // $NON-NLS-1$
61
64
62
    private final JLabeledTextField jmsUser =
65
    private final JLabeledTextField jmsUser =
63
        new JLabeledTextField(JMeterUtils.getResString("jms_user")); // $NON-NLS-1$
66
        new JLabeledTextField(JMeterUtils.getResString("jms_user")); // $NON-NLS-1$
Lines 132-137 Link Here
132
        sampler.setProviderUrl(urlField.getText());
135
        sampler.setProviderUrl(urlField.getText());
133
        sampler.setConnectionFactory(jndiConnFac.getText());
136
        sampler.setConnectionFactory(jndiConnFac.getText());
134
        sampler.setDestination(jmsDestination.getText());
137
        sampler.setDestination(jmsDestination.getText());
138
        sampler.setDurableSubscriptionId(jmsDurableSubscriptionId.getText());
135
        sampler.setUsername(jmsUser.getText());
139
        sampler.setUsername(jmsUser.getText());
136
        sampler.setPassword(jmsPwd.getText());
140
        sampler.setPassword(jmsPwd.getText());
137
        sampler.setUseAuth(useAuth.isSelected());
141
        sampler.setUseAuth(useAuth.isSelected());
Lines 164-169 Link Here
164
        mainPanel.add(urlField);
168
        mainPanel.add(urlField);
165
        mainPanel.add(jndiConnFac);
169
        mainPanel.add(jndiConnFac);
166
        mainPanel.add(createDestinationPane());
170
        mainPanel.add(createDestinationPane());
171
        mainPanel.add(jmsDurableSubscriptionId);
167
        mainPanel.add(useAuth);
172
        mainPanel.add(useAuth);
168
        mainPanel.add(jmsUser);
173
        mainPanel.add(jmsUser);
169
        mainPanel.add(jmsPwd);
174
        mainPanel.add(jmsPwd);
Lines 193-198 Link Here
193
        urlField.setText(sampler.getProviderUrl());
198
        urlField.setText(sampler.getProviderUrl());
194
        jndiConnFac.setText(sampler.getConnectionFactory());
199
        jndiConnFac.setText(sampler.getConnectionFactory());
195
        jmsDestination.setText(sampler.getDestination());
200
        jmsDestination.setText(sampler.getDestination());
201
        jmsDurableSubscriptionId.setText(sampler.getDurableSubscriptionId());
196
        jmsUser.setText(sampler.getUsername());
202
        jmsUser.setText(sampler.getUsername());
197
        jmsPwd.setText(sampler.getPassword());
203
        jmsPwd.setText(sampler.getPassword());
198
        iterations.setText(sampler.getIterations());
204
        iterations.setText(sampler.getIterations());
Lines 212-217 Link Here
212
        urlField.setText(""); // $NON-NLS-1$
218
        urlField.setText(""); // $NON-NLS-1$
213
        jndiConnFac.setText(""); // $NON-NLS-1$
219
        jndiConnFac.setText(""); // $NON-NLS-1$
214
        jmsDestination.setText(""); // $NON-NLS-1$
220
        jmsDestination.setText(""); // $NON-NLS-1$
221
        jmsDurableSubscriptionId.setText(""); // $NON-NLS-1$
215
        jmsUser.setText(""); // $NON-NLS-1$
222
        jmsUser.setText(""); // $NON-NLS-1$
216
        jmsPwd.setText(""); // $NON-NLS-1$
223
        jmsPwd.setText(""); // $NON-NLS-1$
217
        iterations.setText("1"); // $NON-NLS-1$
224
        iterations.setText("1"); // $NON-NLS-1$
(-)src/protocol/jms/org/apache/jmeter/protocol/jms/sampler/SubscriberSampler.java (-5 / +17 lines)
Lines 36-42 Link Here
36
import org.apache.log.Logger;
36
import org.apache.log.Logger;
37
37
38
/**
38
/**
39
 * This class implements the JMS Subcriber sampler.
39
 * This class implements the JMS Subscriber sampler.
40
 * It supports both receive and onMessage strategies via the ReceiveSubscriber class.
40
 * It supports both receive and onMessage strategies via the ReceiveSubscriber class.
41
 * 
41
 * 
42
 */
42
 */
Lines 55-61 Link Here
55
    private static final Logger log = LoggingManager.getLoggerForClass();
55
    private static final Logger log = LoggingManager.getLoggerForClass();
56
56
57
    // Default wait (ms) for a message if timeouts are not enabled
57
    // Default wait (ms) for a message if timeouts are not enabled
58
    // This is the maximimum time the sampler can be blocked.
58
    // This is the maximum time the sampler can be blocked.
59
    private static final long DEFAULT_WAIT = 500L;
59
    private static final long DEFAULT_WAIT = 500L;
60
60
61
    // No need to synch/ - only used by sampler and ClientPool (which does its own synch)
61
    // No need to synch/ - only used by sampler and ClientPool (which does its own synch)
Lines 64-73 Link Here
64
    private transient volatile boolean interrupted = false;
64
    private transient volatile boolean interrupted = false;
65
65
66
    private transient long timeout;
66
    private transient long timeout;
67
    
68
    // ID for durable subscription    
69
    private transient String durableSubscriptionId = null;
67
70
68
    private transient boolean useReceive;
71
    private transient boolean useReceive;
69
72
70
    // This will be null iff initialisation succeeeds.
73
    // This will be null if initialization succeeds.
71
    private transient Exception exceptionDuringInit;
74
    private transient Exception exceptionDuringInit;
72
75
73
    // If true, start/stop subscriber for each sample
76
    // If true, start/stop subscriber for each sample
Lines 76-81 Link Here
76
    // Don't change the string, as it is used in JMX files
79
    // Don't change the string, as it is used in JMX files
77
    private static final String CLIENT_CHOICE = "jms.client_choice"; // $NON-NLS-1$
80
    private static final String CLIENT_CHOICE = "jms.client_choice"; // $NON-NLS-1$
78
    private static final String TIMEOUT = "jms.timeout"; // $NON-NLS-1$
81
    private static final String TIMEOUT = "jms.timeout"; // $NON-NLS-1$
82
    private static final String DURABLE_SUBSCRIPTION_ID = "jms.durableSubscriptionId"; // $NON-NLS-1$
79
    private static final String TIMEOUT_DEFAULT = "";
83
    private static final String TIMEOUT_DEFAULT = "";
80
    private static final String STOP_BETWEEN = "jms.stop_between_samples"; // $NON-NLS-1$
84
    private static final String STOP_BETWEEN = "jms.stop_between_samples"; // $NON-NLS-1$
81
    
85
    
Lines 93-99 Link Here
93
     */
97
     */
94
    private void initListenerClient() throws JMSException, NamingException {
98
    private void initListenerClient() throws JMSException, NamingException {
95
        SUBSCRIBER = new ReceiveSubscriber(0, getUseJNDIPropertiesAsBoolean(), getJNDIInitialContextFactory(),
99
        SUBSCRIBER = new ReceiveSubscriber(0, getUseJNDIPropertiesAsBoolean(), getJNDIInitialContextFactory(),
96
                    getProviderUrl(), getConnectionFactory(), getDestination(), 
100
                    getProviderUrl(), getConnectionFactory(), getDestination(), getDurableSubscriptionId(),
97
                    isUseAuth(), getUsername(), getPassword());
101
                    isUseAuth(), getUsername(), getPassword());
98
        log.debug("SubscriberSampler.initListenerClient called");
102
        log.debug("SubscriberSampler.initListenerClient called");
99
    }
103
    }
Lines 106-112 Link Here
106
    private void initReceiveClient() throws NamingException, JMSException {
110
    private void initReceiveClient() throws NamingException, JMSException {
107
        SUBSCRIBER = new ReceiveSubscriber(getUseJNDIPropertiesAsBoolean(),
111
        SUBSCRIBER = new ReceiveSubscriber(getUseJNDIPropertiesAsBoolean(),
108
                getJNDIInitialContextFactory(), getProviderUrl(), getConnectionFactory(), getDestination(),
112
                getJNDIInitialContextFactory(), getProviderUrl(), getConnectionFactory(), getDestination(),
109
                isUseAuth(), getUsername(), getPassword());
113
                getDurableSubscriptionId(), isUseAuth(), getUsername(), getPassword());
110
        log.debug("SubscriberSampler.initReceiveClient called");
114
        log.debug("SubscriberSampler.initReceiveClient called");
111
    }
115
    }
112
116
Lines 353-358 Link Here
353
    public void setTimeout(String timeout){
357
    public void setTimeout(String timeout){
354
        setProperty(TIMEOUT, timeout, TIMEOUT_DEFAULT);        
358
        setProperty(TIMEOUT, timeout, TIMEOUT_DEFAULT);        
355
    }
359
    }
360
    
361
    public String getDurableSubscriptionId(){
362
        return getPropertyAsString(DURABLE_SUBSCRIPTION_ID);
363
    }
364
365
    public void setDurableSubscriptionId(String durableSubscriptionId){
366
        setProperty(DURABLE_SUBSCRIPTION_ID, durableSubscriptionId);        
367
    }
356
368
357
    // This was the old value that was checked for
369
    // This was the old value that was checked for
358
    private final static String RECEIVE_STR = JMeterUtils.getResString(JMSSubscriberGui.RECEIVE_RSC); // $NON-NLS-1$
370
    private final static String RECEIVE_STR = JMeterUtils.getResString(JMSSubscriberGui.RECEIVE_RSC); // $NON-NLS-1$

Return to bug 50666