Avatar
0
Bảo Ngô Beginner
Bảo Ngô Beginner
Bàn về cách ezy trả response
@Override<p> protected void execute() throws EzyBadRequestException { </p> <p> if (message.length() > 255) { </p> <p> throw new EzyBadRequestException(ChatErrors.MESSAGE_TOO_LONG, "message too long"); </p> <p> } </p> <p> ChatChannelUsers channelUsers = </p> <p> channelUserService.getChannelUsers(channelId, user.getName()); </p> <p> if (channelUsers == null) { </p> <p> throw new EzyBadRequestException(ChatErrors.CHANNEL_NOT_FOUND, "channel with id: " + channelId + " not found"); </p> <p> } </p> <p> messageService.save(new ChatMessage( </p> <p> maxIdService.incrementAndGet(ChatEntities.CHAT_MESSAGE), </p> <p> true, message, channelId, user.getName(), clientMessageId </p> <p> )); </p> <p> responseFactory.newObjectResponse() </p> <p> .command(CHAT_USER_MESSAGE) </p> <p> .param("from", user.getName()) </p> <p> .param("message", message) </p> <p> .param("channelId", channelId) </p> <p> .usernames(channelUsers.getUsers()) </p> <p> .execute(); </p> <p> } </p> <p> Đoạn code trên xử lý request và gửi response cho user. Tuy nhiên e có thắc mắc là tại sao mình ko thiết kế để return 1 cái response entity (ví dụ bên spring) hoặc 1 dto màcác lại return void và để việc response cho developer? </p> <p> Nếu như e có 1 concurrent map/list để cache user lại và sau đó bốc bừa 1 vài user ra để gửi thì sẽ có vấn đề không? </p> <p> Tệ hơn nữa, nếu e cache lại responseFactory và dùng nó cùng với list user để spam message thì có ổn không? </p> <p> Regards </p>
Answer
Avatar
1
Thân Nam Teacher
Thân Nam Teacher
excel-object-mapper
Làm sao để mapping dữ liệu từ file excel sang object java chuẩn và thuận tiện cho việc mở rộng và validate dữ liệu từ file excel để lưu database.
Answer
Avatar
1
Thân Nam Teacher
Thân Nam Teacher
Lỗi font khi đọc từ file properties trong spring boot
Em chào mọi người <p> </p> <p> Em đọc dữ liệu từ file properties của spring bị lỗi font Dự án - &gt; D? �n </p> <p> </p> <p> có cách nào để đọc không bị lỗi font không ạ </p> <p> </p> <p> em đã thử các ví dụ tại <a href="https://www.baeldung.com/java-string-encode-utf-8 " target="_blank">https://www.baeldung.com/java-string-encode-utf-8 </a> cũng không được </p> <p> </p> <p> Em cảm ơn </p>
Answer
Avatar
1
Hồng Quân Nguyễn Beginner
Cách truy vấn và xử lý dữ liệu lớn trong Oracle(table khoảng 50M record)
chào mọi người. <p> </p> <p> Em có một module xử lý bất đồng bộ nhiều tập user(khoảng 2-3M user mỗi tập), mỗi tập user cần truy vấn(với các điều kiện khác nhau tùy vào tập user đó) trong bảng user(có khoảng 50M record). Nếu Mỗi lần xử lý một tập user bất kỳ thì em sẽ truy vấn cả tập user lên chương trình nhưng khi đó việc truy vấn rất chậm và tràn bộ nhớ chương trình nên em có định sẽ cache các id của các tập user đó vào redis theo từng batch và xử lý từng batch user id, để lấy được user cần xử lý thì em sẽ truy vấn theo id(vì id có index nên em nghĩ sẽ nhanh hơn) và không tràn bộ nhớ. Mn thấy cách này có ổn không và có cách nào nhanh hơn không ạ? </p>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Không submit được File trên postman
Em chào mọi người <p> Em đang submit file từ postman để test thì gặp log trên </p> <p> Em cần config gì thêm ở API hay tool postman k ạ </p> <p> em cảm ơn </p> <p> </p> <p> &nbsp; </p> <p> </p> <img class="content-img" src="https://stackask.com/wp-content/uploads/2023/02/Screenshot-2023-02-03-160203.jpg" /><img class="content-img" src="https://stackask.com/wp-content/uploads/2023/02/Screenshot-2023-02-03-160125.jpg" />
Answer
Avatar
1
Hồng Quân Nguyễn Beginner
Synchronous Redis trong Spring boot
chào mn, em có sử dụng Redis trong project của mình. Hiện tại em có 2 module cần thao tác trên một tập thuê bao với tốc độ nhanh(vì nếu truy vấn dưới database thì rất chậm do dữ liệu nhiều).Em hướng sẽ cache hết tập thuê bao này trên Redis. em có 2 hướng: <ol> <li>chỉ cache id và sau đó sẽ truy vấn theo từng id(id có index nên em nghĩ sẽ nhanh)</li> <li>cache cả toàn bộ thông tin nhưng như thế nếu thuê bao cập nhật thông tin thì trên cache sẽ phải đồng bộ như nào.</li> </ol> <ul> <li>cả 2 đều phải lấy dữ liệu kiểu đồng bộ thì trong Java có thư viện nào hỗ trợ không ạ?</li> <li>Nếu cache trên redis mà redis sập, dữ liệu bị mất đi thì phải làm sao ạ?</li> <li>Mn còn ý tưởng nào hay thì góp ý giúp em với :D</li> </ul>
Answer
Avatar
1
Hồng Quân Nguyễn Beginner
kafka serializer và deserializer
hi mn, em đang sử dụng kafka cho sản phẩm của mình. Về việc ser/des thì trong dự án thực tế thì mn hay dùng cách nào để ser/des vậy ạ? em tính sử dụng avro nhưng lại phải cài thêm schema registry vậy nên dùng Json/Protobuf/Avro sẽ tốt hơn ạ?
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Convert cron
Em convert cron sang ngày, thì ngày convert ra cách ngày hiện tại 1 tuần <p> Cron: 0 23 16 ? <em>THU </em> - 2023/01/19 16:23:00 </p> <p> </p> <ul> <li>2023/01/12 16:28:00 </li></ul> <p> Làm cách nào để lấy được ngày giờ hiện tại của cron vậy ạ </p> <p> Code </p> <p> </p> <pre> DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:00"); LOGGER.info("Cron: " + emailConfig.getTimeSendMail()); CronExpression cronExpression = CronExpression.parse("0 23 16 ? * THU"); LocalDateTime nextRunDate = cronExpression.next(LocalDateTime.now()); LOGGER.info(dtf.format(nextRunDate)); LocalDateTime current = LocalDateTime.now(); LOGGER.info(dtf.format(current)); </pre>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Formet String to Json
em chào mọi người làm sao để format chuỗi string thành chuỗi json vậy ạ <p> em sài json note đọc dữ liệu xuất ra: </p> <p> </p> <pre> nationality": {"code": "","description": ""} &lt;/pre&gt; dữ liệu mong muốn &lt;pre&gt; nationality": { "code": "", "description": "" } </pre>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Lấy File tài liệu sau khi nén.
Anh ơi làm sao để lấy File zip trả ra đó để gửi vào tài liệu khi gửi Mail ạ. Hiện tại em đang xuất fle ra 1 ổ mặc định còn xuất ra file để thêm vào tài liệu đính kèm email thì mình làm cách nào ạ. Code: <p> </p> <pre> public void zipFiles(){ FileOutputStream fos = null; ZipOutputStream zipOut = null; FileInputStream fis = null; try { File folder = new File("D:\\Data\\attachment"); File[] attachFiles = folder.listFiles(); fos = new FileOutputStream("C:\\Users\\admin\\Desktop\\tai-lieu\\testing.zip"); zipOut = new ZipOutputStream(new BufferedOutputStream(fos)); for(File file: attachFiles){ fis = new FileInputStream(file); ZipEntry ze = new ZipEntry(file.getName()); System.out.println("Zipping the file: "+file.getName()); zipOut.putNextEntry(ze); byte[] tmp = new byte[1024]; int size = 0; while((size = fis.read(tmp)) != -1){ zipOut.write(tmp, 0, size); } zipOut.flush(); fis.close(); } zipOut.close(); System.out.println("Done... Zipped the files..."); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try{ if(fos != null) fos.close(); } catch(Exception ex){ } } } </pre>
Answer
Avatar
0
Thân Nam Teacher
Thân Nam Teacher
Nén nhiều file tài liệu
Em chào mọi người <p> </p> <p> Cho em hỏi là làm cách nào để giảm kích thước file sau khi nén ạ. </p> <p> Em nén xong thì kích thước file tài liệu bằng tất kích thước các file cộng lại. Code: </p> <p> </p> <pre> public void zipFiles(){ FileOutputStream fos = null; ZipOutputStream zipOut = null; FileInputStream fis = null; try { File folder = new File("D:\\Data\\attachment"); File[] attachFiles = folder.listFiles(); fos = new FileOutputStream("C:\\Users\\admin\\Desktop\\tai-lieu\\testing.zip"); zipOut = new ZipOutputStream(new BufferedOutputStream(fos)); for(File file: attachFiles){ fis = new FileInputStream(file); ZipEntry ze = new ZipEntry(file.getName()); System.out.println("Zipping the file: "+file.getName()); zipOut.putNextEntry(ze); byte[] tmp = new byte[1024]; int size = 0; while((size = fis.read(tmp)) != -1){ zipOut.write(tmp, 0, size); } zipOut.flush(); fis.close(); } zipOut.close(); System.out.println("Done... Zipped the files..."); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try{ if(fos != null) fos.close(); } catch(Exception ex){ } } } </pre>
Answer
Avatar
1
Thân Nam Teacher
Thân Nam Teacher
Getting @Scheduled cron value from database
Em chào mọi người <p> </p> <p> Em đang làm lấy giá trị cron @Scheduled từ cơ sở dữ liệu để làm job tự động vào thời gian cố định, thời gian được lấy từ csdl em muốn hỏi là làm sao để cấu hình lấy được thời gian từ csdl đó em cảm ơn! </p> <p> </p> <p> &nbsp; </p>
Answer