简体   繁体   English

面临问题,同时使用 re.compile python regex 创建列表

[英]facing issue, while creating List with in re.compile python regex

I am trying to create a List with regex in a Python shell.我正在尝试在 Python shell 中使用正则表达式创建一个列表。 In list I have 3 value topic-1, topic-2, topic-3.在列表中,我有 3 个值 topic-1、topic-2、topic-3。 I am creating one consumer object which is having topic and topic should contains 3 values [topic1, topic2, topic3].我正在创建一个具有主题的消费者对象,主题应该包含 3 个值 [topic1、topic2、topic3]。 so Whenever I want to point any one from topic-1, topic-2, topic-3.所以每当我想指出主题 1、主题 2、主题 3 中的任何一个时。 so it should take a message from right topic.所以它应该从正确的主题中获取信息。 I am following below code but it's giving one issue:我正在遵循以下代码,但它给出了一个问题:

import pulsar
import re

client = pulsar.Client('pulsar://localhost:6650')
topic = 'my-topic'
topic = ['topic-1', 'topic-2', 'topic-3']
topic = re.compile('topic-.*')
print(topic)
# <_sre.SRE_Pattern object at 0x7f13314e7210> 
consumer = client.subscribe(topic, "my-subscription")
2019-04-26 07:05:02.956 INFO  ConnectionPool:72 | Created connection for 
pulsar://localhost:6650
2019-04-26 07:05:02.957 INFO  ClientConnection:300 | [127.0.0.1:55874 -> 
127.0.0.1:6650] Connected to broker

Here I am able to create consumer object, But it's not creating with right value like [topic-1, topic-2, topic-3] because in next step I am not able to receive the message.在这里我可以创建消费者对象,但它没有像[topic-1, topic-2, topic-3]这样的正确值创建,因为在下一步中我无法接收消息。 What would be the syntax issue?语法问题是什么?

I can't find anything overtly wrong in your syntax.我在你的语法中找不到任何明显的错误。 Are you sure you have those topics in your namespace?您确定您的名称空间中有这些主题吗? Try using pulsar's command line tools, eg:尝试使用 pulsar 的命令行工具,例如:

pulsar-admin tenants list pulsar-admin 租户列表

pulsar-admin namespaces list <> pulsar-admin 命名空间列表 <>

pulsar-admin topics list tenant/cluster/namespace pulsar-admin 主题列表租户/集群/命名空间

See here for more options: https://pulsar.apache.org/docs/latest/reference/CliTools/有关更多选项,请参见此处: https ://pulsar.apache.org/docs/latest/reference/CliTools/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM