SOLVED
Python - azure-servicebus module
Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Hamder83
11 - Bolide
‎11-03-2022
01:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
Solved! Go to Solution.
Labels:
- Labels:
- Python
3 REPLIES 3
‎11-03-2022
02:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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:
‎11-07-2022
10:11 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
‎03-13-2023
02:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
