小编sha*_*haf的帖子

KafkaMessageListenerContainer 与 ConcurrentMessageListenerContainer

如果我使用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

java messaging spring apache-kafka

8
推荐指数
1
解决办法
1万
查看次数

使用 PIL 保存模式错误将 png 转换为 pdf

我正在尝试将 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)

python-imaging-library python-3.x

6
推荐指数
1
解决办法
5294
查看次数

如何使用 TELETHON 按日期获取消息?

如何获取今天发布的消息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)

python telethon

5
推荐指数
1
解决办法
9605
查看次数

对于排序数组来说,更快地替代 np.where

给定一个沿每行排序的大数组a,是否有比 numpy 更快的替代方法np.where来查找索引,其中min_v <= a <= max_v?\xc2\xa0 我想,利用数组的排序性质应该能够加快速度。

\n\n

np.where这是一个用于在大型数组中查找给定索引的设置示例。

\n\n
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

python arrays numpy where-clause

5
推荐指数
1
解决办法
845
查看次数

Spring Boot“由于不是具体的顶级类而被忽略”

我有这个(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)

java spring spring-data-jpa spring-boot

5
推荐指数
1
解决办法
4513
查看次数

加载 fasttext 预训练的德语词嵌入的 .vec 文件抛出内存不足错误

我正在使用 gensim 加载 fasttext 的预训练词嵌入

de_model = KeyedVectors.load_word2vec_format('wiki.de\wiki.de.vec')

但这给了我一个内存错误。

有什么办法可以加载它吗?

nlp gensim word-embedding fasttext

4
推荐指数
1
解决办法
2430
查看次数

如何用Jackson定义2级继承结构

我有以下基本(界面)结构

@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和类。NotificationReqMessageNotificationMessage …

java json jackson

3
推荐指数
1
解决办法
833
查看次数

@Autowired创建空对象,尽管@configuration

我有以下配置类

@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)

java spring dependency-injection

2
推荐指数
1
解决办法
446
查看次数

问题在Catalina上配置Charles代理

在购买带有Catalina的新MacBook Pro之后启动Charles时,我收到以下消息

当它位于只读卷上时,Charles无法配置您的代理设置

charles-proxy macos-catalina

1
推荐指数
2
解决办法
1059
查看次数

将 24 小时字符串与 Java 进行比较

我有以下 24 小时的字符串表示,例如14231956

我想检查当前时间(带时区)是否在这对之间

我当前的解决方案使用获取一天中的小时和分钟

int h = Instant.now().atZone(ZoneId.systemDefault()).getHour()
int t = Instant.now().atZone(ZoneId.systemDefault()).getMinute()
Run Code Online (Sandbox Code Playgroud)

从数字创建一个 4 位字符串,并进行字符串比较

我根本不喜欢我的解决方案,这样做的优雅方法是什么?

java datetime

1
推荐指数
2
解决办法
60
查看次数

Docker 容器在本地运行 - 没有发送任何数据

我正在尝试在 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)

有人可以帮忙吗。

python docker

1
推荐指数
1
解决办法
2112
查看次数