如果我使用listener.concurrency属性,这会使用KafkaMessageListenerContainer还是ConcurrentMessageListenerContainer?请注意,我没有明确定义任何 bean,并将所需的 bean 创建留给了 spring boot。
我想知道我的理解是否正确。我希望在使用来自具有多个分区(例如 3)的主题的消息时能够并行。那么,如果我按application.yml
如下方式在文件中配置它,可以吗?我尝试了下面的配置,看到创建了 3 个消费者。
spring:
kafka:
consumer:
group-id: group-id
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
producer:
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
listener:
concurrency: 3
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,我是否必须创建一个 bean 来配置ConcurrentMessageListenerContainer
,或者上面的侦听器配置将在内部使用ConcurrentMessageListenerContainer
,而不是KafkaMessageListenerContainer
在它看到时使用listener.concurrency=3
?
我正在尝试将 png 文件转换为 pdf 文件。PIL
似乎是这样做的方法,但我cannot save mode RGBA
在运行时遇到错误 ( )
代码:
import os
import PIL
from PIL import Image
path = 'E:\path_to_file'
filename = '15868799_1.png'
fullpath_filename = os.path.join(path, filename)
im = PIL.Image.open(fullpath_filename)
newfilename = '15868799.pdf'
newfilename_fullpath = os.path.join(path, newfilename)
PIL.Image.Image.save(im, newfilename_fullpath, "PDF", resoultion=100.0)
Run Code Online (Sandbox Code Playgroud)
错误:
File "C:\Python\lib\site-packages\PIL\PdfImagePlugin.py", line 148, in _save
raise ValueError("cannot save mode %s" % im.mode)
ValueError: cannot save mode RGBA
Run Code Online (Sandbox Code Playgroud) 如何获取今天发布的消息TELETHON
我正在使用下面的代码
date_of_post = datetime.datetime(2019, 12, 24)
with TelegramClient(name, api_id, api_hash) as client:
for message in client.iter_messages(chat , offset_date = date_of_post):
print(message.sender_id, ':', message.text)
Run Code Online (Sandbox Code Playgroud) 给定一个沿每行排序的大数组a
,是否有比 numpy 更快的替代方法np.where
来查找索引,其中min_v <= a <= max_v
?\xc2\xa0 我想,利用数组的排序性质应该能够加快速度。
np.where
这是一个用于在大型数组中查找给定索引的设置示例。
import numpy as np\n\n# Initialise an example of an array in which to search\nr, c = int(1e2), int(1e6)\na = np.arange(r*c).reshape(r, c)\n\n# Set up search limits\nmin_v = (r*c/2)-10\nmax_v = (r*c/2)+10\n\n# Find indices of occurrences\nidx = np.where(((a >= min_v) & (a <= max_v)))\n
Run Code Online (Sandbox Code Playgroud)\n 我有这个(https://github.com/Danix43/HerculesAPI)由Java和Spring Boot制作的REST应用程序。
当由于某种原因@SpringBootApplication
注释不再找到TermometruService
带有@Service
.
我已经尝试了从使用@ComponentScan
服务包开始的所有操作,但任何 Rest 操作都会返回RESOURCE_NOT_FOUND
更改 jdk 版本和刷新 Maven 存储库。
2020-01-27 19:33:39.635 DEBUG 6248 --- [main] o.s.c.a.ClassPathBeanDefinitionScanner : Ignored because not a concrete top-level class: file [D:\Programe\Programare\Java\HerculesAPI\target\classes\com\herculesapi\services\TermometruService.class]
Run Code Online (Sandbox Code Playgroud) 我正在使用 gensim 加载 fasttext 的预训练词嵌入
de_model = KeyedVectors.load_word2vec_format('wiki.de\wiki.de.vec')
但这给了我一个内存错误。
有什么办法可以加载它吗?
我有以下基本(界面)结构
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "messageType",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = AppMessage.class, name = "APP"),
@JsonSubTypes.Type(value = NotificationMessage.class, name = "NOTIFICATION"),
})
public interface Message {
MessageType getMessageType();
Date getTimestamp();
}
Run Code Online (Sandbox Code Playgroud)
该类AppMessage
是一个简单的 POJO(目前),例如
public class AppMessage implements Message {
private String appId;
...
private Date timestamp = Date.from(Instant.now());
}
Run Code Online (Sandbox Code Playgroud)
但这NotificationMessage
是另一个界面
public class AppMessage implements Message {
private String appId;
...
private Date timestamp = Date.from(Instant.now());
}
Run Code Online (Sandbox Code Playgroud)
当然还有另外两个实现 的pojo asNotificationAckMessage
和类。NotificationReqMessage
NotificationMessage …
我有以下配置类
@org.springframework.context.annotation.Configuration
public class TemplateConfiguration {
@Bean
public Configuration configuration() {
Configuration configuration = new Configuration(new Version(2, 3, 23));
configuration.setClassForTemplateLoading(TemplateConfiguration.class, "/templates/");
configuration.setDefaultEncoding("UTF-8");
configuration.setLocale(Locale.US);
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
return configuration;
}
}
Run Code Online (Sandbox Code Playgroud)
我在下面的@service中使用它
@Service
public class FreeMarkerService {
@Autowired
private Configuration configuration;
private static final Logger logger = LoggerFactory.getLogger(FreeMarkerService.class);
public String process() {
try {
Template template = configuration.getTemplate("someName");
....
} catch (IOException | TemplateException e) {
logger.error("Error while processing FreeMarker template: " + e);
throw new RuntimeException(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试像这样调用process()时
FreeMarkerService f …
Run Code Online (Sandbox Code Playgroud) 在购买带有Catalina的新MacBook Pro之后启动Charles时,我收到以下消息
当它位于只读卷上时,Charles无法配置您的代理设置
我有以下 24 小时的字符串表示,例如1423
和1956
我想检查当前时间(带时区)是否在这对之间
我当前的解决方案使用获取一天中的小时和分钟
int h = Instant.now().atZone(ZoneId.systemDefault()).getHour()
int t = Instant.now().atZone(ZoneId.systemDefault()).getMinute()
Run Code Online (Sandbox Code Playgroud)
从数字创建一个 4 位字符串,并进行字符串比较
我根本不喜欢我的解决方案,这样做的优雅方法是什么?
我正在尝试在 docker 容器中运行一个基本的烧瓶应用程序。docker build 工作正常,但是当我尝试在本地进行测试时,我得到了
127.0.0.1 没有发送任何数据错误。
文件
FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.7
ENV LISTEN_PORT=5000
EXPOSE 5000
RUN pip install --upgrade pip
WORKDIR /app
ADD . /app
CMD ["python3","main.py","--host=0.0.0.0"]
Run Code Online (Sandbox Code Playgroud)
主文件
import flask
from flask import Flask, request
import os
app = Flask(__name__)
@app.route('/')
def this_works():
return "This works..."
if __name__ == '__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
运行我正在使用的容器的命令是:
docker run -it --name dockertestapp1 --rm -p 5000:5000 dockertestapp1
Run Code Online (Sandbox Code Playgroud)
还要构建的命令是:
docker build --tag dockertestapp1 .
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗。
java ×5
python ×3
spring ×3
apache-kafka ×1
arrays ×1
datetime ×1
docker ×1
fasttext ×1
gensim ×1
jackson ×1
json ×1
messaging ×1
nlp ×1
numpy ×1
python-3.x ×1
spring-boot ×1
telethon ×1
where-clause ×1