<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/opt/local/share/tsung/tsung-1.0.dtd">
<tsung loglevel="debug" version="1.0">
	<clients>
		<client host="ubuntu" maxusers="5"></client>
	</clients>

	<servers>
        <server host="127.0.0.1" port="5672" type="tcp" />
	</servers>

	<load duration="72" unit="hour">
        <user session="amqp_consumer" start_time="1" unit="second"></user>

		<arrivalphase phase="1" duration="3" unit="second">
			<users maxnumber="1" arrivalrate="1" unit="second"/>
		</arrivalphase>
	</load>

	<options>
        <!--amqp config: username and password -->
        <option type="ts_amqp" name="username" value="guest" />
        <option type="ts_amqp" name="password" value="guest" />

        <!--amqp heartbeat timeout: 30s (default 600s)-->
        <option type="ts_amqp" name="heartbeat" value="30" />
	</options>

	<sessions>
		<session probability="100" name="amqp_publisher" type="ts_amqp" bidi="true">
            <request>
                <amqp type="connection.open" vhost="/"></amqp>
            </request>

            <!--  open channel, channel id is from 1 to 10 -->
            <for from="1" to="10" incr="1" var="loops">
                <request>
                    <amqp type="channel.open"></amqp>
                </request>
            </for>

            <!-- ignore this request if you don't need publisher confirm -->
            <for from="1" to="10" incr="1" var="loops">
                <request subst="true">
                    <amqp type="confirm.select" channel="%%_loops%%"></amqp>
                </request>
            </for>
            
            <for from="1" to="10" incr="1" var="loops">
                <for from="1" to="100" incr="1" var="counter">
                    <transaction name="publish">
                        <!-- specify payload_size to have tsung generate a payload for you -->
                        <request subst="true">
                            <amqp type="basic.publish" channel="%%_loops%%" exchange="test_exchange" routing_key="test_queue" persistent="true" payload_size="100"></amqp>
                        </request>
                        <!-- substitutions are supported on the payload. Payload will override payload_size. -->
                        <request subst="true">
                            <amqp type="basic.publish" channel="%%_loops%%" exchange="test_exchange" routing_key="test_queue" persistent="true" payload="Test Payload"></amqp>
                        </request>
                    </transaction>
                </for>

                <!-- if publish with confirm, add a waitForConfirms request as you need: timeout=1s -->
                <request>
                    <amqp type="waitForConfirms" timeout="1"></amqp>
                </request>
            </for>

            <for from="1" to="10" incr="1" var="loops">
                <request subst="true">
                    <amqp type="channel.close" channel="%%_loops%%"></amqp>
                </request>
            </for>

            <request>
                <amqp type="connection.close"></amqp>
            </request>
		</session>
		<session probability="0" name="amqp_consumer" type="ts_amqp" bidi="true">
            <request>
                <amqp type="connection.open"></amqp>
            </request>

            <for from="1" to="10" incr="1" var="loops">
                <request>
                    <amqp type="channel.open"></amqp>
                </request>
            </for>

            <!-- ignore this request if you don't need qos(prefetch_count only) -->
            <for from="1" to="10" incr="1" var="loops">
                <request subst="true">
                    <amqp type="basic.qos" channel="%%_loops%%" prefetch_count="200"></amqp>
                </request>
            </for>

            <for from="1" to="10" incr="1" var="loops">
                <request subst="true">
                    <amqp type="basic.consume" channel="%%_loops%%" queue="test_queue" ack="true"></amqp>
                </request>
            </for>

            <!-- wait to receive messages from the server: timeout=180s -->
            <request>
                <amqp type="waitForMessages" timeout="180"></amqp>
            </request>

            <for from="1" to="10" incr="1" var="loops">
                <request subst="true">
                    <amqp type="channel.close" channel="%%_loops%%"></amqp>
                </request>
            </for>

            <request>
                <amqp type="connection.close"></amqp>
            </request>
		</session>
	</sessions>
</tsung>
