Search code examples
jmeter

How to call JMeter time function once per JMS Publisher sampler execution and use the resulting value in multiple places in the same sampler?


I have a JMS Publisher sampler in which I want to use the value of the JMeter time function in 2 places (JMS properties and text body) but I need the value generated only once per sampler execution so that I can use the same value in both places of the same sampler.

The problem is that this function is called once when I put it in the JMS Properties section and a 2nd time when I put it in the request Object message text body and I get 2 slightly different values which is not what I want. I only need to use one value in both places. This is the function call I use: {__time(yyyyMMddHHmmssSSS)}

Can someone please give me an idea of how I could proceed?

I was thinking that I need a preprocessor to be executed before the Publisher sampler which would give me a variable populated and then I could use that value, but I don't know which preprocessor. I was familiar with JSR223 Preprocessor usage but sadly, I can't use the JMeter function call in a JSR223 sampler.


Solution

  • There is 2nd argument in the __time() function where you can specify the name of JMeter Variable to store the result in.

    So if you change your function call to:

    ${__time(yyyyMMddHHmmssSSS,timestamp)}
    

    you will be able to refer the generated value as ${timestamp} where required

    enter image description here

    More information on JMeter Functions concept: Apache JMeter Functions - An Introduction