# Custom Feeders with multi values

**URL:** <https://community.gatling.io/t/custom-feeders-with-multi-values/1524>\
**Category:** Gatling (Open-Source)\
**Created:** [October 9, 2014, 11:59pm UTC](https://community.gatling.io/t/custom-feeders-with-multi-values/1524 "2014-10-09T23:59:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Santhosh](https://community.gatling.io/u/Santhosh)\
**Post date:** [October 9, 2014, 11:59pm UTC](https://community.gatling.io/t/custom-feeders-with-multi-values/1524/1 "2014-10-09T23:59:10Z")

</div>

Hi

I have a request where 3 header parameters need to be generated dynamically.

Example: timestamp, userid , token

token is calculated based on userid and timestamp.

val getUserScenario = scenario(“Get User”)  
.feed(customFeeder)  
.exec(

http(“Get User”)  
.get("/user")  
.header(“timestamp”,"${timeStampStr}")  
.header(“userid”, “${userid}”)  
.header(“token”, “${token}”)  
.check(status.is(200))

I am trying to use custom Feeder for this by over riding default feeder

object customFeed {

val customFeeder = new Feeder[String] {

override def hasNext = true

override def next: Map[String, String] = {

val sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss.SSS”)  
sdf.setTimeZone(TimeZone.getTimeZone(“UTC”))

val strUserid = abs(ThreadLocalRandom.current().nextLong(10000000000L)).toString

val timeStamp = DateTime.now()  
val now = new Date(timeStamp.getMillis())  
val timeStampStr = sdf.format(now)

…  
…  
…  
…

val timeStampStr = sdf.format(now)  
val strUserid = abs(ThreadLocalRandom.current().nextLong(10000000000L)).toString  
val token : String = … Calculated by complex math…based on timestamp and userid

**Map(“timeStampStr” → timeStampStr)**  
**Map(“token”-\> token)**  
**Map(“userid” →** strUserid\*\*)\*\*

}

}

When i try to use this in get Call mentioned above, it only recognizes the last parameter in Map. That is **Map(“upmId” → strUpmId).** It is not recognizing timStampStr attribute and hashedToken attribute.

Please help me with is scenario.

Regards,  
Santhosh

---

<div class="post-metadata">

**Author:** ![agr](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@agr](https://community.gatling.io/u/agr)\
**Post date:** [October 10, 2014, 2:06am UTC](https://community.gatling.io/t/custom-feeders-with-multi-values/1524/2 "2014-10-10T02:06:28Z")

</div>

//Do this:

val myFeeder = Iterator.continually( myFun() )  
.map(s =\> Map[String, String](s.\_1 → s.\_2, s.\_3 → s.\_4, s.\_5 → s.\_6)

//Now you just need a function, myFunction() which returns a 6-tuple containing:

def myFun: (String, String, String, String, String, String) = {  
(“timeStampStr”, timeStampStrFunction(), “token”, tokenFunction(), “userid”, userIdStrFunction())  
}

//Now you need those functions . . .

def timeStampStrFunction(): String = {}  
def tokenFunction(): String = {}

def userIdStrFunction(): String = {}

//Just make sure those functons return the strings you want, and everything will be evaluated when you call next on the iterator, so you get correct results regarding time and stuff

//Also, on a side note, I didn’t test any of this or whatever, so I might’ve made some syntax error or something somewhere

---

<div class="post-metadata">

**Author:** ![Santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Santhosh](https://community.gatling.io/u/Santhosh)\
**Post date:** [October 10, 2014, 3:40am UTC](https://community.gatling.io/t/custom-feeders-with-multi-values/1524/3 "2014-10-10T03:40:50Z")

</div>

Thank you 🙂 exactly what i am looking for

That worked like a charm. !!!

Cheers  
Santhosh
