You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Pat Gell <pa...@gmail.com> on 2022/05/24 08:43:40 UTC

JMSPublisher payload scripting

Hello,

I'm stuck again with Jmeter tests.
I want to send a JSON text message via JMSPublisher to ActiveMQ.
Example Payload:
*{*
*  "id": "123-456",*
*  "correlationId": "123-098-789",*
*  "rooms": [*
*    {*
*      "id": "r1",*
*      "rNumber": 321,*
*      "location": {*
*        "id": "L1",*
*        "city": "Munich"*
*      }*
*    },*
    *{*
*      "id": "r2",*
*      "rNumber": 42,*
*      "location": {*
*        "id": "L1",*
*        "city": "Munich"*
*      }*
*    }*
*  ]*
*}*

Is it possible to create the payload with multiple room objects via script
(e.g groovy)?
Could you provide an example how to script the rooms objects in the
JMSPublisher payload?

Best regards,
Patrick

Re: JMSPublisher payload scripting

Posted by Pat Gell <pa...@gmail.com>.
With your tip about the JSR223 PreProcessor I'm able to construct my JSON.

Thank you very much for your help!!!


Best regards
Patrick

Am Di., 24. Mai 2022 um 11:25 Uhr schrieb Dmitri T <gl...@live.com>:

> Not sure what do you mean by "rooms objects" but JSON can be created
> using any suitable JSR223 Test Element
> <https://jmeter.apache.org/usermanual/best-practices.html#jsr223> and
> JsonBuilder
> <http://docs.groovy-lang.org/next/html/gapi/groovy/json/JsonBuilder.html>.
>
> Example code:
>
> def payload = [:]
>
> payload.put('id','123-456')
> payload.put('correlationId','123-098-789')
>
> def rooms = []
>
> 1.upto(2,{ def room = [id:"r$it",rNumber: it,location:
> [id:"L1",city:"Munich"]]
>      rooms.add(room)
> })
>
> payload.put('rooms',rooms)
>
> vars.put('payload',new groovy.json.JsonBuilder(payload).toPrettyString())
>
> The generated value can be referred as *${payload}* later on where
> required.
>
> More information:
>
>   * Apache Groovy - Parsing and producing JSON
>     <https://groovy-lang.org/processing-json.html>
>   * Apache Groovy - Why and How You Should Use It
>     <https://www.blazemeter.com/blog/groovy-new-black>
>
>
> On 5/24/2022 10:43 AM, Pat Gell wrote:
> > Hello,
> >
> > I'm stuck again with Jmeter tests.
> > I want to send a JSON text message via JMSPublisher to ActiveMQ.
> > Example Payload:
> > *{*
> > *  "id": "123-456",*
> > *  "correlationId": "123-098-789",*
> > *  "rooms": [*
> > *    {*
> > *      "id": "r1",*
> > *      "rNumber": 321,*
> > *      "location": {*
> > *        "id": "L1",*
> > *        "city": "Munich"*
> > *      }*
> > *    },*
> >      *{*
> > *      "id": "r2",*
> > *      "rNumber": 42,*
> > *      "location": {*
> > *        "id": "L1",*
> > *        "city": "Munich"*
> > *      }*
> > *    }*
> > *  ]*
> > *}*
> >
> > Is it possible to create the payload with multiple room objects via
> script
> > (e.g groovy)?
> > Could you provide an example how to script the rooms objects in the
> > JMSPublisher payload?
> >
> > Best regards,
> > Patrick
> >

Re: JMSPublisher payload scripting

Posted by Dmitri T <gl...@live.com>.
Not sure what do you mean by "rooms objects" but JSON can be created 
using any suitable JSR223 Test Element 
<https://jmeter.apache.org/usermanual/best-practices.html#jsr223> and 
JsonBuilder 
<http://docs.groovy-lang.org/next/html/gapi/groovy/json/JsonBuilder.html>.

Example code:

def payload = [:]

payload.put('id','123-456')
payload.put('correlationId','123-098-789')

def rooms = []

1.upto(2,{ def room = [id:"r$it",rNumber: it,location: [id:"L1",city:"Munich"]]
     rooms.add(room)
})

payload.put('rooms',rooms)

vars.put('payload',new groovy.json.JsonBuilder(payload).toPrettyString())

The generated value can be referred as *${payload}* later on where 
required.

More information:

  * Apache Groovy - Parsing and producing JSON
    <https://groovy-lang.org/processing-json.html>
  * Apache Groovy - Why and How You Should Use It
    <https://www.blazemeter.com/blog/groovy-new-black>


On 5/24/2022 10:43 AM, Pat Gell wrote:
> Hello,
>
> I'm stuck again with Jmeter tests.
> I want to send a JSON text message via JMSPublisher to ActiveMQ.
> Example Payload:
> *{*
> *  "id": "123-456",*
> *  "correlationId": "123-098-789",*
> *  "rooms": [*
> *    {*
> *      "id": "r1",*
> *      "rNumber": 321,*
> *      "location": {*
> *        "id": "L1",*
> *        "city": "Munich"*
> *      }*
> *    },*
>      *{*
> *      "id": "r2",*
> *      "rNumber": 42,*
> *      "location": {*
> *        "id": "L1",*
> *        "city": "Munich"*
> *      }*
> *    }*
> *  ]*
> *}*
>
> Is it possible to create the payload with multiple room objects via script
> (e.g groovy)?
> Could you provide an example how to script the rooms objects in the
> JMSPublisher payload?
>
> Best regards,
> Patrick
>