<p>I am using Azure Kubernetes Service(AKS) platform and used KEDA &quot;ScaledJob&quot; for long running job. In this, Azure Service Bus Queue trigger has been used to auto trigger Jobs. Now while I am adding messages in Azure Service Bus, KEDA will auto trigger job and create node/pod as per configuration. but in this case, all the messages are getting picked up and processed by some pods. it is expected that each scaled up pod processes single message and terminates.</p>
<p>following is my yml file</p>
<pre><code>apiVersion: keda.sh/v1alpha1
kind: ScaledJob
metadata:
  name: {{ .Chart.Name }}
spec:
  jobTargetRef:
    backoffLimit: 4
    parallelism: 1
    completions: 1
    activeDeadlineSeconds: 300
    template:
      spec:
        imagePullSecrets:
          - name: {{ .Values.image.imagePullSecrets }}
        terminationGracePeriodSeconds: 30
        dnsPolicy: ClusterFirst
        volumes:
          - name: azure
            azureFile:
              shareName: sharenameone
              secretName: secret-sharenameone
              readOnly: true
          - name: one-storage
            emptyDir: {}
          - name: &quot;logging-volume-file&quot;
            persistentVolumeClaim:
              claimName: &quot;azure-file-logging&quot;        
        initContainers:
          - name: test-java-init
            image: {{ .Values.global.imageRegistryURI }}/{{ .Values.image.javaInitImage.name}}:{{ .Values.image.javaInitImage.tag }}
            imagePullPolicy: {{ .Values.image.pullPolicy }}
            securityContext:
              readOnlyRootFilesystem: true
            resources:
              requests:
                cpu: 100m
                memory: 300Mi
              limits:
                cpu: 200m
                memory: 400Mi
            volumeMounts:
              - name: azure
                mountPath: /mnt/azure
              - name: one-storage
                mountPath: /certs
        containers:
          - name: {{ .Chart.Name }}
            image: {{ .Values.global.imageRegistryURI }}/tests/{{ .Chart.Name }}:{{ .Values.version }}
            imagePullPolicy: {{ .Values.image.pullPolicy }}
            env:
              {{- include &quot;chart.envVars&quot; . | nindent 14 }}
              - name: JAVA_OPTS
                value: &gt;-
                    {{ .Values.application.javaOpts }}          
              - name: application_name
                value: &quot;test_application&quot;
              - name: queueName
                value: &quot;test-queue-name&quot;
              - name: servicebusconnstrenv
                valueFrom: 
                  secretKeyRef:
                    name: secrets-service-bus
                    key: service_bus_conn_str
            volumeMounts:
              - name: cert-storage
                mountPath: /certs
              - name: &quot;logging-volume-azure-file&quot;
                mountPath: &quot;/mnt/logging&quot;
            resources:
              {{- toYaml .Values.resources | nindent 14 }}                   
  pollingInterval: 30
  maxReplicaCount: 5
  successfulJobsHistoryLimit: 5
  failedJobsHistoryLimit: 20
  triggers:
  - type: azure-servicebus
    metadata:
      queueName: &quot;test-queue-name&quot;
      connectionFromEnv: servicebusconnstrenv
      messageCount: &quot;1&quot;

</code></pre>
<p>and this is my azure function listener</p>
<pre><code> @FunctionName(&quot;TestServiceBusTrigger&quot;)
  public void TestServiceBusTriggerHandler(
      @ServiceBusQueueTrigger(
              name = &quot;msg&quot;,
              queueName = &quot;%TEST_QUEUE_NAME%&quot;,
              connection = &quot;ServiceBusConnectionString&quot;)
          final String inputMessage,
      final ExecutionContext context) {

    final java.util.logging.Logger contextLogger = context.getLogger();
    System.setProperty(&quot;javax.net.ssl.trustStore&quot;, &quot;/certs/cacerts&quot;);
   
    try {
      // all the processing goes here 
    } catch (Exception e) {
     //Exception handling
    }
  }
</code></pre>
<p>what configurations needs to be added, so that each scaled up pod processes single message and terminates?</p>

DeveloperSSP208
<p>This is not how Azure Functions were designed, or rather even how KEDA should be used in general. It would be more ideal if the already running container processes as many messages as it can once provisioned.</p>
<p>That being said, if your scenario still requires this, you could write a simple script that directly uses the <a href="https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-java-how-to-use-queues?tabs=passwordless" rel="nofollow noreferrer">Azure Service Bus SDK</a> to fetch just one message, process it, and terminate.</p>
