We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Python - azure-servicebus module

Hamder83
11 - Bolide

Hi 

I don't know any python programming, but im trying to pass one or more messages to our servicebus.
If I pass two  code works:

if I pass one row only, it phrases my string into rows.

And I have no clue how to write this code. I know this is not a python forum, but still maybe im lucky.



from ayx import Alteryx
from azure.servicebus import ServiceBusClient, ServiceBusMessage

import os
connstr = "xxxxx"
queue_name = "invoicedk"
df = Alteryx.read("#1")


alteryxMessage = df.squeeze()
#print(ServiceBusMessage)

for specificationRows in alteryxMessage:
    with ServiceBusClient.from_connection_string(connstr) as client:
        with client.get_queue_sender(queue_name) as sender:
        # Sending a single message
            single_message = ServiceBusMessage(specificationRows)
            sender.send_messages(single_message)

        # Sending a list of messages
        #messages = [ServiceBusMessage("First message"), ServiceBusMessage("Second message")]
        #sender.send_messages(messages)

 

I hope someone can help

3 REPLIES 3
Hamder83
11 - Bolide

Thought I could do something like this:

df = Alteryx.read("#1")

alteryxMessage = df.squeeze()

rowCount = alteryxMessage.count()



#print(ServiceBusMessage)
if rowCount == 1:
    with ServiceBusClient.from_connection_string(connstr) as client:
        with client.get_queue_sender(queue_name) as sender:
        # Sending a single message
            single_message = ServiceBusMessage(alteryxMessage)
            sender.send_messages(single_message)
    
else:  
    for specificationRows in alteryxMessage:
        with ServiceBusClient.from_connection_string(connstr) as client:
            with client.get_queue_sender(queue_name) as sender:
            # Sending a single message
                single_message = ServiceBusMessage(specificationRows)
                sender.send_messages(single_message)

 

But i get this error:

Hamder83_0-1667469130813.png

 

Hamder83
11 - Bolide

Just as info, got it working like this:

from ayx import Package
from ayx import Alteryx
import pandas as pd
from azure.servicebus import ServiceBusClient, ServiceBusMessage
import os

connstr = "xxx"
#connstr = "xxx"
queue_name = "invoicedk"
df = Alteryx.read("#1")

series = pd.Series(df['JSON'], index=df.index)

for specificationRows in series:
    with ServiceBusClient.from_connection_string(connstr) as client:
        with client.get_queue_sender(queue_name) as sender:
          
            
            single_message = ServiceBusMessage(specificationRows)
            sender.send_messages(single_message)

   

 

 

VasylStrogush
5 - Atom

Hi mate,

could you please share piece of code how do you install azure package in alterix application?
I assumed it has to look like -> 

Package.installPackages(['azure-servicebus'])

but looks it does not work properly.

 

Thank you in advance.

Labels
Top Solution Authors