Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

Monday, 10 December 2018

[RocketMQ] Quick Start in RaspberryPi(Ubuntu)

 RocketMQ

  • 낮은 latency와 고성능으로 분산 메시징과 스트리밍 처리를 제공하는 플랫폼이다. 메시지의 신뢰성을 보장하고, 조 단위의 처리량과 유연한 확장성을 자랑한다.
  •  알리바바가 2012년부터 다량의 메시지를 처리하기 위해서, Apache ActiveMQ 5.13 버전 기반에서 분산 아키텍처를 도입하여 개발하기 시작했다. 2016년 11월에 알리바바가 Apache 재단에 danation 하고, 2017년 2월에 Apache Top-Level 프로젝트로 선정되었다.









1. Download install file and unzip

Prerequisite : 
    64bit OS, Linux/Unix/Mac is recommended;
    64bit JDK 1.8+;
    Maven 3.2.x;
    Git;
    4g+ free disk for Broker server

$ wget http://mirror.navercorp.com/apache/rocketmq/{version}/rocketmq-all-{version}-bin-release.zip
$ unzip rocketmq-all-{version}-bin-realase.zip









2. Setup environment variables


$ vi ~/.profile

[edit]

$ . ~/.profile

export ROCKETMQ_HOME=[installed_directory]
export PATH=$PATH:$ROCEKTMQ_HOME/bin
export NAMESRV_ADDR={host}:{port}    # for Name server connector address









3. Startup Name Server




3.1. Run Error -> Edit JVM Options


$ vi $ROCKETMQ_HOME/bin/runserver.sh

[Edit : Optimize memory size in your system]





3.2 Start Name Server in background


$ nohup mqnamesrv > $ROCKETMQ_HOME/log/mqnamesrv.log  2>&1 &
$ tail -f $ROCKETMQ_HOME/log/mqnamesrv.log






4. Start Broker Server


$ nohup mqbroker > $ROCKETMQ_HOME/log/mqbroker.log  2>&1 &
$ tail -f $ROCKETMQ_HOME/log/mqbroker.log






4.1. Run Error -> Edit JVM Options


$ vi $ROCKETMQ_HOME/bin/runbroker.sh

[Edit : Optimize memory size in your system]









5. Test Message Produce/Consume

5.1. Start Producer


$ sh $ROCKETMQ_HOME/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer





5.2. Start Consumer


$ sh $ROCKETMQ_HOME/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer






6. Shutdown


# Shutdown Broker
$ mqshutdown broker

# Shutdown Name Server
# mqshtudown namesrv







References

RocketMQ Tutorial
RocketMQ WiKi

Tuesday, 27 November 2018

[AWS] S3(Simple Storage Service) Tutorial

awscli 를 이용한 간단한 S3 사용 튜토리얼

1. S3 접근 권한 유저 생성

1.1 유저 생성











1.2. 그룹 생성 및 사용자 추가












2. AWS CLI 설정



$ aws configure





3. 버킷 리스트 출력 (ls : List)

$ aws s3 ls
$ aws s3 ls s3://[BUCKET_NAME]
$ aws s3 ls s3:/[BUCKET_NAME]/[PATH]






4. 버킷 생성 (mb : Make Bucket)

$ aws s3 mb s3://[BUCKET_NAME]





5. 버킷 제거 (rb : Remove Bucket)

$ aws s3 rb s3://[BUCKET_NAME]





6. 업로드 / 다운로드 (cp : Copy)

6.1 업로드

$ aws s3 cp [LOCAL_FILE] s3://[BUCKET_NAME]/[PATH]
$ aws s3 cp [LOCAL_DIRECTORY]  s3://[BUCKET_NAME]/[PATH]
$ aws s3 cp [LOCAL_DIRECTORY]  s3://[BUCKET_NAME]/[PATH] --recursive












6.2. 다운로드


$ aws s3 cp s3://[BUCKET_NAME]/[PATH] [LOCAL_FILE]






7. 파일 제거 (rm : Remove)


$ aws s3 rm s3://[BUCKET_NAME]/[FILE_PATH]
$ aws s3 rm s3://[BUCKET_NAME]/[DIRCTORY_PATH] --recursive


Wednesday, 23 May 2018

[Java] NIO DatagramChannel Tutorial

DatagramChannel Receiver


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 *****************************************************************
 * 
 * NIOUDPRecvTest.java
 * 
 * NIO DatagramChannel Receiver
 *
 *****************************************************************
 *
 * @version 1.0.0 2017-10-11 dorbae 최초생성
 * @since 1.0.0
 * @author dorbae
 *
 */
package test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class NIOUDPRecvTest {

 /**
  *
  * @version 1.0.0 2017-10-11 dorbae 최초생성
  * @since 1.0.0
  * @author dorbae
  *
  * @param args
  */
 public static void main(String[] args) {
  DatagramChannel channel = null;
  try {
   channel = DatagramChannel.open();
   channel.socket().bind(new InetSocketAddress("localhost", 9000));

  } catch (IOException e) {
   e.printStackTrace();
   System.exit(1);
  }
  
  ByteBuffer buf = ByteBuffer.allocate(256);
  byte[] buffer = new byte[256];
  int limit = 0;
  try {
   while (true) {
    buf.clear();
    try {
     System.out.println("\nWaiting...");
     channel.receive(buf);
     limit = buf.limit();
     System.out.println("buf.limit()=" + limit);
     System.out.println("buf.capacity()=" + buf.capacity());
     System.out.println("buf.position()=" + buf.position());
     System.out.println("buf.arrayOffset()=" + buf.arrayOffset());

     buf.flip();
     limit = buf.limit();
     System.out.println("buf.limit()=" + limit);

     buf.get(buffer, 0, limit);

     System.out.println("data=" + new String(buffer, 0, limit, "utf8"));

    } catch (IOException e) {
     break;
    }

   }

  } catch (Exception e) {
   e.printStackTrace();
  
  } finally {
   if (channel != null)
    try {
     channel.close();
    } catch (IOException e) {}
  }
  
 } 

}



DatagramChannel Sender


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 *****************************************************************
 * 
 * NIOUDPSendTest.java
 * 
 * NIO DatagramChannel Sender
 *
 *****************************************************************
 *
 * @version 1.0.0 2017-10-11 dorbae 최초생성
 * @since 1.0.0
 * @author dorbae
 *
 */
package test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class NIOUDPSendTest {

 /**
  *
  * @version 1.0.0 2017-10-11 dorbae 최초생성
  * @since 1.0.0
  * @author dorbae
  *
  * @param args
  * @throws IOException 
  */
 public static void main(String[] args) throws IOException {
  String message = "한글 String to write to file..." + System.currentTimeMillis();

  
  DatagramChannel channel = DatagramChannel.open();
  
  
  ByteBuffer buf = ByteBuffer.allocate(256);
  buf.clear();
  buf.put(message.getBytes("utf8"));
  buf.flip();

  int bytesSent = channel.send(buf, new InetSocketAddress("localhost", 9000));

 }

}