Samplers — HTTP, JDBC, FTP, JMS

8 min read

Samplers are the elements that actually send requests. Every time a JMeter thread executes a sampler, it sends a request, waits for a response, records the result, and moves on. The sampler is where the work happens — everything else in the test plan (timers, config elements, assertions, listeners) exists to support samplers.

JMeter's sampler library is one of its biggest competitive advantages. K6 has an excellent HTTP module and growing support for other protocols, but JMeter ships with direct support for a range of protocols that most modern tools leave to plugins or workarounds.

HTTP Request sampler

The HTTP Request sampler is the workhorse of most JMeter test plans. It handles REST APIs, web pages, GraphQL, SOAP-over-HTTP, and file uploads.

Basic configuration:

FieldExampleNotes
Server Nameapi.example.comHostname only, no https://
Port443Leave blank to use protocol default
Protocolhttpshttp or https
MethodPOSTGET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
Path/api/v1/usersStarts with /

Sending a JSON body (POST/PUT):

Click the Body Data tab and paste raw JSON:

{
  "username": "${username}",
  "email": "${email}"
}

The ${variable} syntax references JMeter variables set via CSV Data Set Config, User-Defined Variables, or extractors. This is how you parameterise requests without hardcoding values.

Sending query parameters:

Click the Parameters tab and add name/value pairs. JMeter URL-encodes them and appends them to the URL automatically.

HTTP Headers:

Add an HTTP Header Manager as a child of the sampler (or at Thread Group level to apply globally). The Header Manager lets you set Content-Type: application/json, Authorization: Bearer ${token}, or any custom header.

JDBC Request sampler

The JDBC Request sampler sends SQL queries directly to a database via a JDBC driver. This is JMeter's killer feature for enterprise testing — K6 has no native database testing capability.

Setup requires two elements:

  1. JDBC Connection Configuration (Config Element): defines the connection pool, driver class, JDBC URL, username, and password. Add this at Thread Group level.

  2. JDBC Request (Sampler): specifies the SQL query to execute.

Example configuration for PostgreSQL:

JDBC Connection Configuration:
  Pool Name: pgPool
  Max # of Connections: 10
  Driver Class: org.postgresql.Driver
  Database URL: jdbc:postgresql://localhost:5432/mydb
  Username: testuser
  Password: testpass
-- In the JDBC Request sampler:
SELECT COUNT(*) AS order_count
FROM orders
WHERE status = 'pending'
  AND created_at > NOW() - INTERVAL '1 hour'

Store the query result in a variable using the Variable Names field — then you can reference ${order_count} in subsequent samplers or assertions to validate database state during the test.

The JDBC driver JAR must be in $JMETER_HOME/lib/ before JMeter starts. PostgreSQL, MySQL, Oracle, MSSQL, and H2 all have freely available JDBC JARs.

JMeter Samplers
  • – HTTP Request (REST, SOAP, GraphQL)
  • – HTTP/2 Sampler (plugin)
  • – WebSocket (plugin)
  • – JDBC Request (any SQL database)
  • – MongoDB (plugin)
  • – Redis (plugin)
  • – JMS Publisher (send to queue/topic)
  • – JMS Subscriber (consume messages)
  • – Kafka (plugin)
  • TCP Sampler (raw TCP) –
  • FTP Request (upload/download) –
  • SMTP Sampler (email) –
  • Java Request (custom Java class) –

FTP Request sampler

The FTP Request sampler uploads or downloads files to/from an FTP server. Configuration fields: server, port, remote filename, local filename, username, password, and the operation (get/put).

FTP testing is niche but relevant in financial services and healthcare systems where batch file transfers over FTP are still common workflows.

JMS samplers

Java Message Service (JMS) is the standard messaging API for Java enterprise systems. JMeter includes two JMS samplers:

JMS Publisher — sends messages to a JMS destination (queue or topic). Configure the JNDI initial context factory, provider URL, and destination name. Drop the JMS provider's JAR (ActiveMQ, IBM MQ, RabbitMQ's JMS client) into lib/.

JMS Subscriber — consumes messages from a JMS destination. Useful for verifying that a system publishes expected messages as a side effect of HTTP requests (for example, confirming a purchase event appears on a message bus after a checkout API call).

JMS Point-to-Point — a combined sampler for request/reply messaging patterns.

Java Request sampler

The Java Request sampler calls a custom Java class that implements JMeter's JavaSamplerClient interface. This is the escape hatch for protocols JMeter does not support natively — if you can write a Java client for it, you can load test it with JMeter.

For scripting without compilation, use JSR223 Sampler with Groovy (covered in Chapter 5). Groovy scripts in JSR223 Sampler give you full Java library access without a separate compile-and-deploy cycle.

TCP Sampler

The TCP Sampler opens a raw TCP socket and sends a configurable payload, then reads the response. Use it for:

  • Custom binary protocols
  • Line-delimited text protocols
  • Legacy financial messaging systems (FIX protocol, SWIFT variants via custom parsers)

Naming samplers matters

Every sampler result uses its Name field as the label in listeners, HTML reports, and Grafana dashboards. JMeter's default name "HTTP Request" is useless when you have 20 HTTP requests.

Name every sampler to reflect what it does:

POST /api/auth/login
GET /api/products?category=${category}
JDBC: select order count for user ${user_id}

This makes listener output, HTML reports, and distributed test result aggregation meaningful without post-processing.

⚠️ Common mistakes

  • Hardcoding credentials in JDBC Connection Configuration. Test plans with hardcoded database passwords get committed to version control. Use JMeter properties (${__P(db.password,)}) and pass the actual value via CLI -J flag or a user.properties file excluded from git.
  • Forgetting to add the JDBC driver JAR. JMeter cannot find the JDBC driver class at startup if the JAR is not in lib/. The error (Driver class not found) appears in the log, not in the sampler result. Always restart JMeter after adding a JAR to lib/.
  • Not naming samplers. The default name "HTTP Request" appears in every listener, every report, and every Grafana panel. When you have 15 HTTP requests all named "HTTP Request", debugging a performance regression is nearly impossible. Rename every sampler before you add the second one.

🎯 Practice task

Extend your test plan with multiple sampler types.

  1. Open first-test.jmx. Rename the existing HTTP Request to "GET / (homepage)".
  2. Add a second HTTP Request targeting test.k6.io/crocodiles/ with method GET. Name it "GET /crocodiles/ (list)".
  3. Add a third HTTP Request with method POST targeting test.k6.io/crocodiles/. In the Body Data tab, enter: {"name": "Sobek", "sex": "M", "date_of_birth": "2010-06-10"}. Set Content-Type: application/json via an HTTP Header Manager. Name it "POST /crocodiles/ (create)".
  4. Run with 1 user, 1 loop. In View Results Tree, confirm all three requests show different labels and that the POST request shows the JSON body in the Request tab.
  5. Check the response codes — the POST to a public test server may return 401 (authentication required) or a 2xx depending on the server configuration. Note what the response code is and what the response body says.

If you have a local PostgreSQL or MySQL instance available: configure a JDBC Connection Configuration and add a JDBC Request with SELECT NOW(). Confirm JMeter can execute the query and return a result.

// tip to track lessons you complete and pick up where you left off across devices.