Skip to main content

django micro service app.

Project description

djmicroservice

django restfull框架下的微服务应用包。

一. 安装

  • 依赖包

    • django >=2.0
    • djangorestframework >=3.8
    • djangorestframework-jwt >=1.6
    • djkeeper >=0.2
    • South >=1.0
    • coreapi >=2.3.3
    • simple-rest-client >=0.5.2
    • stomp.py >=4.1.20
  • 安装

     #pip install -r requirements.txt
     #python setup.py install
    
  • 配置

    • django 配置

      • INSTALLED_APPS配置项增加
       INSTALLED_APPS = [
       	'django.contrib.auth',
       	'django.contrib.contenttypes',
       	'django.contrib.sessions',
       	'django.contrib.messages',
       	'django.contrib.staticfiles',    
       	'rest_framework',
       	'djmicroservice',
       ]
      
      • 增加 REST_FRAMEWORK配置项
      REST_FRAMEWORK = {
          'DEFAULT_PERMISSION_CLASSES': (
          ),
          'DEFAULT_AUTHENTICATION_CLASSES': (
              'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
          ),
      }
      
      • 增加 REST_FRAMEWORK配置项
       REST_FRAMEWORK = {
       	'DEFAULT_PERMISSION_CLASSES': (
       	),
       	'DEFAULT_AUTHENTICATION_CLASSES': (
       		'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
       	),
       }
      
      • 增加 JWT_AUTH配置项
       JWT_AUTH = {
       	'JWT_ENCODE_HANDLER':'rest_framework_jwt.utils.jwt_encode_handler',		
       	'JWT_DECODE_HANDLER':'rest_framework_jwt.utils.jwt_decode_handler',		
       	'JWT_PAYLOAD_HANDLER':'user.jwt.handlers.onlyuser_jwt_payload_handler',		
       	'JWT_PAYLOAD_GET_USER_ID_HANDLER':'rest_framework_jwt.utils.jwt_get_user_id_from_payload_handler',		
       	'JWT_RESPONSE_PAYLOAD_HANDLER':'user.jwt.handlers.onlyuser_jwt_response_payload_handler',		
       	'JWT_SECRET_KEY': SECRET_KEY,
       	'JWT_GET_USER_SECRET_KEY': None,
       	'JWT_PUBLIC_KEY': None,
       	'JWT_PRIVATE_KEY': None,
       	'JWT_ALGORITHM': 'HS256',
       	'JWT_VERIFY': True,
       	'JWT_VERIFY_EXPIRATION': True,
       	'JWT_LEEWAY': 0,
       	'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=36000),
       	'JWT_AUDIENCE': None,
       	'JWT_ISSUER': None,		
       	'JWT_ALLOW_REFRESH': True,
       	'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),		
       	'JWT_AUTH_HEADER_PREFIX': 'JWT',
       	'JWT_AUTH_COOKIE': None,		
       }
      
      • 增加 DJMICROSERVICE配置项
       DJMICROSERVICE = { 
       	#微服务名字
       	'NAME': DEFAULT_NAME ,
       	#微服务URL
       	'URL': 'http://127.0.0.1:8000/',
       	#是否是主节点
       	'MASTER': True, 
       	#微服务资源
       	'RESOURCES': {        
       	}, 
       	#服务发现配置 
       	'DISCOVER': {
       		#是否注册
       		'REGISTER': False,
       		#心跳
       		'HEARTBEAT': 15,
       		#发现者引擎 
       		'ENGINE': 'djmicroservice.discovers.backends.StaticDiscover',
       		#引擎配置
       		'OPTIONS': {
       			'SERVICES':[
       			]
       		},
       	},
       	#客户端配置
       	'CLIENT':{        
       		#认证管理微服务名
       		'AUTH': None,
       		'OBTAIN': None,
       		'REFRESH': None,
       		'VERIFY': None,
       		'USER': None,
       		'PASSWORD': None,
       		'JWT_HEADER_PFX': 'JWT',
       		'TIMEOUT': 2,
       		'AUTO_LOGIN': False,
       	},  
       	#消息队列端配置  
       	'MQ':{
       		#消息队列引擎
       		'ENGINE': 'djmicroservice.mq.backends.ActiveMQ',
       		#引擎配置
       		'OPTIONS': {
       			#消息服务器地址,可以多个
       			'SERVERS': [('127.0.0.1',61613)],
       			#消息服务器登录名
       			'USER': 'admin',
       			#消息服务器密码
       			'PASSWORD': 'admin',
       		},
       		'HANDLERS': { 
       		},
       	},
       	'SERVICE_MANAGER':{
       		#服务管理地址
       		'BIND':('127.0.0.1',56560),
       		'AUTH_KEY':None,
       		#要启动的服务
       		'SERVICES':[        
       			('onlyuser.mq.service.MQService', 1),
       		]
       	}
       }
      

二. RESTful API规范

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djmicroservice-1.0.7.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djmicroservice-1.0.7-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file djmicroservice-1.0.7.tar.gz.

File metadata

  • Download URL: djmicroservice-1.0.7.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

File hashes

Hashes for djmicroservice-1.0.7.tar.gz
Algorithm Hash digest
SHA256 8bf6380ba7749554635c4cf9ee49acf2a8408fe947dfc3ec577ea197b71e08eb
MD5 d7116406d7961e087e0a5790854c3cbf
BLAKE2b-256 9d474f2420b77cc35b5a70fbb2d75a049aab35e19b441c46ff9c5f94abbf5315

See more details on using hashes here.

File details

Details for the file djmicroservice-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: djmicroservice-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

File hashes

Hashes for djmicroservice-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c2d24e245cfdbe0733941464b568e37c2c2d2c1af49acdf98e680f3e5fe27c56
MD5 90603107dbcec16b9b6567896b77e18b
BLAKE2b-256 0b2e02a614d5af2296ff543303dd1e2207ca72d091cadc727090f3ff260c9d87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page