当我尝试用新的对象(从xml文件解析)中插入我的对象时,我遇到了一些问题,但是我收到以下错误:
MongoError: exception: After applying the update to the document {_id: ObjectId('55be3c8f79bae4f80c6b17f8') , ...}, the (immutable) field '_id' was found to have been altered to _id: ObjectId('55be5f15ae
5597401724aab3')
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
xmlFile.product_list.product.forEach(function (product) {
var productEntity = new Product({
product_id: parseInt(product.id),
parent_id: parseInt(product.parent_id),
sku: product.sku,
title: product.title,
pricenormal: parseFloat(product.price_normal),
pricewholesale: parseFloat(product.price_wholesale),
pricewholesalelarge: parseFloat(product.price_wholesale_large),
pricesale: parseFloat(product.price_sale),
weight: parseFloat(product.weight),
volume: parseFloat(product.volume),
unittype: product.unit_type,
status: product.status,
datecreating: product.datecreating,
sp: product.sp,
guaranteeext: product.guarantee_ext,
used: product.used,
statusfull: product.status_full,
description: null,
url: null
});
items.push(productEntity);
});
items.forEach(function (product) …Run Code Online (Sandbox Code Playgroud) 我像Cheerio一样解析我的请求:
var url = http://shop.nag.ru/catalog/16939.IP-videonablyudenie-OMNY/16944.IP-kamery-OMNY-c-vario-obektivom/16704.OMNY-1000-PRO;
request.get(url, function (err, response, body) {
console.log(body);
$ = cheerio.load(body);
console.log($(".description").html());
});
Run Code Online (Sandbox Code Playgroud)
作为输出,我看到内容,但在不可读的奇怪编码:
//Plain body console.log(body) (p.s. russian chars):
<h1><span style="font-size: 16px;">??????? 3?? IP HD ?????? OMNY - ?????????? ????? ?????</span></h1><p style
// cheerio's console.log $(".description").html()
<h1><span style="font-size: 16px;">Уличная 3Мп IP HD камера OMNY
Run Code Online (Sandbox Code Playgroud)
目标URL链接编码采用UTF-8格式.那么为什么Cheerio会破坏我的编码呢?
试图使用iconv来编码我的身体反应:
var body1 = iconv.decode(body, "utf-8");
Run Code Online (Sandbox Code Playgroud)
但console.log($(".description").html());仍然会返回奇怪的文字.
我尝试保留具有一对多关系的父实体:
@Entity
public class TrainEx {
private Set<TrainCompositionEx> trainCompositionsByTrainId;
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "trainByTrainId")
public Set<TrainCompositionEx> getTrainCompositionsByTrainId() {
return trainCompositionsByTrainId;
}
public void setTrainCompositionsByTrainId(Set<TrainCompositionEx> trainCompositionsByTrainId) {
this.trainCompositionsByTrainId = trainCompositionsByTrainId;
}
...
}
Run Code Online (Sandbox Code Playgroud)
和子实体:
@Entity
public class TrainCompositionEx{
@Id
@ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "trainId", referencedColumnName = "trainId", nullable = false, insertable = true, updatable = true)
private TrainEx trainByTrainId;
....
}
Run Code Online (Sandbox Code Playgroud)
所以我从 json POST 端点收到我的 TrainEx trainEx:
@RequestMapping(method= RequestMethod.POST, consumes = "application/json", produces …Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一种方法来重新排序主题分区中的消息并将有序消息发送到新主题.
我有Kafka发布者发送以下格式的String消息:
{system_timestamp}-{event_name}?{parameters}
例如:
1494002667893-client.message?chatName=1c&messageBody=hello
1494002656558-chat.started?chatName=1c&chatPatricipants=3
Run Code Online (Sandbox Code Playgroud)
此外,我们为每条消息添加一些消息密钥,以将它们发送到相应的分区.
我想要做的是根据消息的{system-timestamp}部分重新排序事件,并在1分钟的窗口内,因为我们的发布者不保证将根据{system-timestamp}值发送消息.
例如,我们可以向主题提供首先具有更大{system-timestamp}值的消息.
我已经调查了Kafka Stream API并找到了一些关于消息窗口化和聚合的例子:
Properties streamsConfiguration = new Properties();
streamsConfiguration.put(StreamsConfig.APPLICATION_ID_CONFIG, "stream-sorter");
streamsConfiguration.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
streamsConfiguration.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "localhost:2181");
streamsConfiguration.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
streamsConfiguration.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
KStreamBuilder builder = new KStreamBuilder();
KStream<String, String> stream = builder.stream("events");
KGroupedStream<String>, String> groupedStream = stream.groupByKey();//grouped events within partion.
/* commented since I think that I don't need any aggregation, but I guess without aggregation I can't use time windowing.
KTable<Windowed<String>, String> windowedEvents = stream.groupByKey().aggregate(
() -> "", …Run Code Online (Sandbox Code Playgroud) 也许你可以帮助我,当我在Intellij Idea 13打开我的项目时,我遇到了一个奇怪的apache maven的问题.当项目打开时,我在外部库部分没有库.在diff的模块的所有pom.xml文件中,我看到错误"无法重新连接".

我试图使无效的缓存/重启想法,尝试使用Maven Reimport,但问题仍然存在.但是如果我做mvn clean install,并部署我的项目一切正常.我使用Maven 3.2.3.和Java 1.8.
Maven设置:

Aded idea.log文件:
2015-06-03 11:54:24,585 [ 441715] INFO - #org.jetbrains.idea.maven - Cannot reconnect.
java.lang.RuntimeException: Cannot reconnect.
at org.jetbrains.idea.maven.server.RemoteObjectWrapper.perform(RemoteObjectWrapper.java:98)
at org.jetbrains.idea.maven.server.MavenEmbedderWrapper.resolveProject(MavenEmbedderWrapper.java:97)
at org.jetbrains.idea.maven.project.MavenProjectReader.resolveProject(MavenProjectReader.java:462)
at org.jetbrains.idea.maven.project.MavenProject.resolve(MavenProject.java:624)
at org.jetbrains.idea.maven.project.MavenProjectsTree.resolve(MavenProjectsTree.java:1215)
at org.jetbrains.idea.maven.project.MavenProjectsProcessorResolvingTask.perform(MavenProjectsProcessorResolvingTask.java:42)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor.doProcessPendingTasks(MavenProjectsProcessor.java:131)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor.access$100(MavenProjectsProcessor.java:28)
at org.jetbrains.idea.maven.project.MavenProjectsProcessor$2.run(MavenProjectsProcessor.java:107)
at org.jetbrains.idea.maven.utils.MavenUtil$6.run(MavenUtil.java:440)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:419)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:149)
Caused by: java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:351)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at …Run Code Online (Sandbox Code Playgroud) 请帮我.我在VisualVM中分析我的堆转储.
如何获得值=="0"的所有字符串的数量?我有以下查询:
select count(s) from java.lang.String s where s.toString().equals("0");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我想收到所有字符串的数量为"0"值,如果它们的大小可能在内存中.
我需要在里面画两条弯曲的红色圆圈,如下所示:
上部字符串总是3个字符长度下部字符串可以是1到20个字符长度
UPDATE1: 我尝试使用textpath和circle标签,但我想我需要更改一些坐标:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="40" cy="40" r="24" style="stroke:#006600; fill:none"/>
<defs>
<path id="myTextPath"
d="M75,20
a1,1 0 0,0 150,0"
/>
</defs>
<text x="5" y="50" style="stroke: #000000;">
<textPath xlink:href="#myTextPath" >
string
</textPath>
</text>
</svg>Run Code Online (Sandbox Code Playgroud)
我也没有清楚地理解<path>'d'属性,但我发现我可以改变起点M10,20但是如何改变文本曲线方向?
d="M10,20 a1,1 0 0,0 150,0"
Run Code Online (Sandbox Code Playgroud) 我正在使用Kafka控制台使用者来使用包含多个分区的主题消息:
kafka-console-consumer.bat --bootstrap-server localhost:9092 --from-beginning --topic events
Run Code Online (Sandbox Code Playgroud)
但它只打印邮件正文.有没有办法打印记录元数据或分区号?因为我想知道消息来自哪里.
我已经探讨了控制台消费者文档http://documentation.kamanja.org/_static/command-ref/kafka-console-consumer.pdf,但未找到任何相关属性.
更新:
因此,我认为唯一的解决方案是覆盖DefaultMessageFormatter.class(我们可以通过使用--formatter属性运行kafka console consumer来设置它)并添加在#writeTo(..)方法中打印记录元数据的自定义逻辑.
我已经使用spring-kafka lib实现了 Kafka 消费者。我有一个带有 2 个分区的 Kafka 主题,并且我将ConcurrentKafkaListenerContainerFactory并发级别设置为 2,因此每个容器实例都应该根据 spring-kafka文档从单个分区中使用。
KafkaMessageListenerContainer 接收来自单个线程上所有主题/分区的所有消息。ConcurrentMessageListenerContainer 委托给 1 个或多个 KafkaMessageListenerContainer 以提供多线程消费。
有我的消费者类:
@Component
public class KafkaConsumer {
private HashMap<String, LinkedBlockingQueue<Event>> hashMap = new HashMap<>();
@KafkaListener(topics = "${kafka.topic}", groupId = "events_group")
public void receive(ConsumerRecord<?, ?> record, Consumer consumer) throws InterruptedException {
String message = record.value().toString();
Event event = EventFactory.createEvent(message);
String customerId = event.getAttributeStringValue(DefinedField.CUSTOMER_ID);
// add event to hashMap
LinkedBlockingQueue<Event> queue = hashMap.get(customerId);
if (queue == null) {
queue = …Run Code Online (Sandbox Code Playgroud) 有人可以解释我如何在所有迭代完成后才能进行回调吗?我为此使用了 async.each 函数:
async.each(products, function (product, callback) {
fs.appendFile('ParseLog.txt', "PRODUCT name: " + product.name, function (err) {
console.log("iterate");
callback();
});
}, function (err) {
console.log("ALL FINISH");
});
Run Code Online (Sandbox Code Playgroud)
所以我的输入看起来像:
ALL FINISH
iterate
iterate
iterate
...
Run Code Online (Sandbox Code Playgroud)
但我希望在所有迭代后都会打印“ALL FINISH”消息。
编辑 1:
对不起,但似乎在 if(i > 10) return callback({ data: 'hi'}); // stop每个循环开始时都有问题。我只想在 11 次迭代后退出,但我很奇怪为什么它最初会回调。?
async.each(products, function (product, callback) {
var i = products.indexOf(product);
if(i > 10) return callback({ data: 'hi'}); // stop
fs.appendFile('ParseLog.txt', "PRODUCT name: " + product.name, function (err) {
console.log("iterate");
callback(); …Run Code Online (Sandbox Code Playgroud) 我有 spring 4+ hibernate 4.3 + psql 9.5 应用程序,并遇到了驼峰字段转换的一些问题。
Hibernate: select trainservi0_.trainServiceId as trainSer1_16_, trainservi0_.category as category2_16_, trainservi0_.date as date3_16_, trainservi0_.description as descript4_16_, trainservi0_.name as name5_16_, trainservi0_.status as status6_16_, trainservi0_.trainNumber as trainNum7_16_, trainservi0_.version as version8_16_ from tms.public.train_service trainservi0_
2016-02-29 13:09:34 WARN SqlExceptionHelper:144 - SQL Error: 0, SQLState: 42703
2016-02-29 13:09:34 ERROR SqlExceptionHelper:146 - ERROR: column trainservi0_.trainserviceid does not exist
Perhaps you meant to reference the column "trainservi0_.trainServiceId".
Run Code Online (Sandbox Code Playgroud)
这是我的配置:
public class DataBaseProdConfig {
@Resource
private Environment env;
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() …Run Code Online (Sandbox Code Playgroud) 我创建了依赖于以下 pub/sub doc 的java pub/sub 消费者。
public static void main(String... args) throws Exception {
TopicName topic = TopicName.create(pubSubProjectName, pubSubTopic);
SubscriptionName subscription = SubscriptionName.create(pubSubProjectName, "ssvp-sub");
SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create();
subscriptionAdminClient.createSubscription(subscription, topic, PushConfig.getDefaultInstance(), 0);
MessageReceiver receiver =
new MessageReceiver() {
@Override
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
System.out.println("Got message: " + message.getData().toStringUtf8());
consumer.ack();
}
};
Subscriber subscriber = null;
try {
subscriber = Subscriber.defaultBuilder(subscription, receiver).build();
subscriber.addListener(
new Subscriber.Listener() {
@Override
public void failed(Subscriber.State from, Throwable failure) {
// Handle failure. …Run Code Online (Sandbox Code Playgroud) java ×8
node.js ×3
apache-kafka ×2
hibernate ×2
javascript ×2
jpa ×2
spring ×2
asynchronous ×1
cheerio ×1
encoding ×1
jvisualvm ×1
maven ×1
maven-3 ×1
messaging ×1
mongodb ×1
oql ×1
spring-kafka ×1
stream ×1
svg ×1
visualvm ×1